diff options
author | zeripath <art27@cantab.net> | 2021-02-10 02:50:44 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-10 10:50:44 +0800 |
commit | f82b1dd7c384e0295530f2ded53c0938f7b2fc9b (patch) | |
tree | 60308c77693db06d01cdb5915e3264625752fa60 /models/consistency.go | |
parent | 30f7ddb833adfe276a93c1a79e243b8d33bdd41e (diff) | |
download | gitea-f82b1dd7c384e0295530f2ded53c0938f7b2fc9b.tar.gz gitea-f82b1dd7c384e0295530f2ded53c0938f7b2fc9b.zip |
Prevent adding nil label to .AddedLabels or .RemovedLabels (#14623)
* Prevent adding nil label to .AddedLabels or .RemovedLabels
There are possibly a few old databases out there with malmigrated data that can
cause panics with empty labels being migrated.
This PR adds a few tests to prevent nil labels being added.
Fix #14466
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Add doctor command to remove the broken label comments
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models/consistency.go')
-rw-r--r-- | models/consistency.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/models/consistency.go b/models/consistency.go index f689261a55..aa46e787f1 100644 --- a/models/consistency.go +++ b/models/consistency.go @@ -305,3 +305,13 @@ func CountWrongUserType() (int64, error) { func FixWrongUserType() (int64, error) { return x.Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Cols("type").NoAutoTime().Update(&User{Type: 1}) } + +// CountCommentTypeLabelWithEmptyLabel count label comments with empty label +func CountCommentTypeLabelWithEmptyLabel() (int64, error) { + return x.Where(builder.Eq{"type": CommentTypeLabel, "label_id": 0}).Count(new(Comment)) +} + +// FixCommentTypeLabelWithEmptyLabel count label comments with empty label +func FixCommentTypeLabelWithEmptyLabel() (int64, error) { + return x.Where(builder.Eq{"type": CommentTypeLabel, "label_id": 0}).Delete(new(Comment)) +} |