-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix /api/tasks leads to 500 server error (#5700)
- Fixed re-deleting of skeleton sublabels (attempt to remove already removed sublabels) ![Screenshot from 2023-02-13 10-00-03](https://user-images.githubusercontent.com/49231913/218693868-0afcde6a-935a-4d3f-bfa4-c1793a367f90.png) - Updated Label model (added `project` to `unique_together`) - Added migration to remove or rename wrong labels
- Loading branch information
1 parent
05b9941
commit 8dc272f
Showing
8 changed files
with
196 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
cvat/apps/engine/migrations/0064_delete_or_rename_wrong_labels.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
|
||
from django.db import migrations | ||
from cvat.apps.engine.log import get_migration_logger | ||
|
||
def delete_or_rename_wrong_labels(apps, schema_editor): | ||
migration_name = os.path.splitext(os.path.basename(__file__))[0] | ||
with get_migration_logger(migration_name) as log: | ||
log.info('\nDeleting skeleton Labels without skeletons...') | ||
|
||
Label = apps.get_model('engine', 'Label') | ||
for label in Label.objects.all(): | ||
if label.type == "skeleton" and not hasattr(label, "skeleton"): | ||
label.delete() | ||
|
||
log.info('\nDeleting duplicate skeleton sublabels and renaming duplicate Labels...') | ||
for name, parent, project, task in Label.objects.values_list("name", "parent", "project", "task").distinct(): | ||
duplicate_labels = Label.objects.filter(name=name, parent=parent, project=project) | ||
if task is not None: | ||
duplicate_labels = Label.objects.filter(name=name, parent=parent, task=task) | ||
|
||
if len(duplicate_labels) > 1: | ||
label = duplicate_labels[0] | ||
if label.parent is not None: | ||
label.delete() | ||
else: | ||
for i, label in enumerate(duplicate_labels[1:]): | ||
label.name = f"{label.name}_duplicate_{i + 1}" | ||
label.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('engine', '0063_delete_jobcommit'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=delete_or_rename_wrong_labels | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 3.2.18 on 2023-02-21 09:31 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('engine', '0064_delete_or_rename_wrong_labels'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name='label', | ||
unique_together=set(), | ||
), | ||
migrations.AddConstraint( | ||
model_name='label', | ||
constraint=models.UniqueConstraint(condition=models.Q(('parent__isnull', True), ('task__isnull', True)), fields=('project', 'name'), name='project_name_unique'), | ||
), | ||
migrations.AddConstraint( | ||
model_name='label', | ||
constraint=models.UniqueConstraint(condition=models.Q(('parent__isnull', True), ('project__isnull', True)), fields=('task', 'name'), name='task_name_unique'), | ||
), | ||
migrations.AddConstraint( | ||
model_name='label', | ||
constraint=models.UniqueConstraint(condition=models.Q(('task__isnull', True)), fields=('project', 'name', 'parent'), name='project_name_parent_unique'), | ||
), | ||
migrations.AddConstraint( | ||
model_name='label', | ||
constraint=models.UniqueConstraint(condition=models.Q(('project__isnull', True)), fields=('task', 'name', 'parent'), name='task_name_parent_unique'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.