Added more logs to try debuging the issue with labels (#5694)

main
Andrey Zhavoronkov 3 years ago committed by GitHub
parent 6bf098cfb1
commit a72f5d1f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -642,24 +642,27 @@ class TaskWriteSerializer(WriteOnceMixin, serializers.ModelSerializer):
sublabels = label.pop('sublabels', []) sublabels = label.pop('sublabels', [])
svg = label.pop('svg', '') svg = label.pop('svg', '')
db_label = models.Label.objects.create(task=db_task, parent=parent_label, **label) db_label = models.Label.objects.create(task=db_task, parent=parent_label, **label)
logger.info(f'label:create: Label id:{db_label.id} for spec:{label} with sublabels:{sublabels}, parent_label:{parent_label}')
create_labels(sublabels, parent_label=db_label) create_labels(sublabels, parent_label=db_label)
if db_label.type == str(models.LabelType.SKELETON): if db_label.type == str(models.LabelType.SKELETON):
for db_sublabel in list(db_label.sublabels.all()): for db_sublabel in list(db_label.sublabels.all()):
svg = svg.replace(f'data-label-name="{db_sublabel.name}"', f'data-label-id="{db_sublabel.id}"') svg = svg.replace(f'data-label-name="{db_sublabel.name}"', f'data-label-id="{db_sublabel.id}"')
models.Skeleton.objects.create(root=db_label, svg=svg) db_skeleton = models.Skeleton.objects.create(root=db_label, svg=svg)
logger.info(f'label:create Skeleton id:{db_skeleton.id} for label_id:{db_label.id}')
for attr in attributes: for attr in attributes:
if attr.get('id', None): if attr.get('id', None):
del attr['id'] del attr['id']
models.AttributeSpec.objects.create(label=db_label, **attr) models.AttributeSpec.objects.create(label=db_label, **attr)
create_labels(labels)
task_path = db_task.get_dirname() task_path = db_task.get_dirname()
if os.path.isdir(task_path): if os.path.isdir(task_path):
shutil.rmtree(task_path) shutil.rmtree(task_path)
os.makedirs(db_task.get_task_logs_dirname()) os.makedirs(db_task.get_task_logs_dirname())
os.makedirs(db_task.get_task_artifacts_dirname()) os.makedirs(db_task.get_task_artifacts_dirname())
logger = slogger.task[db_task.id]
create_labels(labels)
db_task.save() db_task.save()
return db_task return db_task
@ -674,16 +677,22 @@ class TaskWriteSerializer(WriteOnceMixin, serializers.ModelSerializer):
instance.subset = validated_data.get('subset', instance.subset) instance.subset = validated_data.get('subset', instance.subset)
labels = validated_data.get('label_set', []) labels = validated_data.get('label_set', [])
logger = slogger.task[instance.id]
def update_labels(labels, parent_label=None): def update_labels(labels, parent_label=None):
for label in labels: for label in labels:
sublabels = label.pop('sublabels', []) sublabels = label.pop('sublabels', [])
svg = label.pop('svg', '') svg = label.pop('svg', '')
db_label = LabelSerializer.update_instance(label, instance, parent_label) db_label = LabelSerializer.update_instance(label, instance, parent_label)
if db_label:
logger.info(f'label:update Label id:{db_label.id} for spec:{label} with sublabels:{sublabels}, parent_label:{parent_label}')
else:
logger.info(f'label:delete label:{label} with sublabels:{sublabels}, parent_label:{parent_label}')
update_labels(sublabels, parent_label=db_label) update_labels(sublabels, parent_label=db_label)
if label.get('id') is None and db_label.type == str(models.LabelType.SKELETON): if label.get('id') is None and db_label.type == str(models.LabelType.SKELETON):
for db_sublabel in list(db_label.sublabels.all()): for db_sublabel in list(db_label.sublabels.all()):
svg = svg.replace(f'data-label-name="{db_sublabel.name}"', f'data-label-id="{db_sublabel.id}"') svg = svg.replace(f'data-label-name="{db_sublabel.name}"', f'data-label-id="{db_sublabel.id}"')
models.Skeleton.objects.create(root=db_label, svg=svg) db_skeleton = models.Skeleton.objects.create(root=db_label, svg=svg)
logger.info(f'label:update Skeleton id:{db_skeleton.id} for label_id:{db_label.id}')
if instance.project_id is None: if instance.project_id is None:
update_labels(labels) update_labels(labels)
@ -870,24 +879,27 @@ class ProjectWriteSerializer(serializers.ModelSerializer):
sublabels = label.pop('sublabels', []) sublabels = label.pop('sublabels', [])
svg = label.pop('svg', []) svg = label.pop('svg', [])
db_label = models.Label.objects.create(project=db_project, parent=parent_label, **label) db_label = models.Label.objects.create(project=db_project, parent=parent_label, **label)
logger.info(f'label:create Label id:{db_label.id} for spec:{label} with sublabels:{sublabels}, parent_label:{parent_label}')
create_labels(sublabels, parent_label=db_label) create_labels(sublabels, parent_label=db_label)
if db_label.type == str(models.LabelType.SKELETON): if db_label.type == str(models.LabelType.SKELETON):
for db_sublabel in list(db_label.sublabels.all()): for db_sublabel in list(db_label.sublabels.all()):
svg = svg.replace(f'data-label-name="{db_sublabel.name}"', f'data-label-id="{db_sublabel.id}"') svg = svg.replace(f'data-label-name="{db_sublabel.name}"', f'data-label-id="{db_sublabel.id}"')
models.Skeleton.objects.create(root=db_label, svg=svg) db_skeleton = models.Skeleton.objects.create(root=db_label, svg=svg)
logger.info(f'label:create Skeleton id:{db_skeleton.id} for label_id:{db_label.id}')
for attr in attributes: for attr in attributes:
if attr.get('id', None): if attr.get('id', None):
del attr['id'] del attr['id']
models.AttributeSpec.objects.create(label=db_label, **attr) models.AttributeSpec.objects.create(label=db_label, **attr)
create_labels(labels)
project_path = db_project.get_dirname() project_path = db_project.get_dirname()
if os.path.isdir(project_path): if os.path.isdir(project_path):
shutil.rmtree(project_path) shutil.rmtree(project_path)
os.makedirs(db_project.get_project_logs_dirname()) os.makedirs(db_project.get_project_logs_dirname())
logger = slogger.project[db_project.id]
create_labels(labels)
return db_project return db_project
# pylint: disable=no-self-use # pylint: disable=no-self-use
@ -898,18 +910,24 @@ class ProjectWriteSerializer(serializers.ModelSerializer):
instance.bug_tracker = validated_data.get('bug_tracker', instance.bug_tracker) instance.bug_tracker = validated_data.get('bug_tracker', instance.bug_tracker)
labels = validated_data.get('label_set', []) labels = validated_data.get('label_set', [])
logger = slogger.project[instance.id]
def update_labels(labels, parent_label=None): def update_labels(labels, parent_label=None):
for label in labels: for label in labels:
sublabels = label.pop('sublabels', []) sublabels = label.pop('sublabels', [])
svg = label.pop('svg', '') svg = label.pop('svg', '')
db_label = LabelSerializer.update_instance(label, instance, parent_label) db_label = LabelSerializer.update_instance(label, instance, parent_label)
if db_label:
logger.info(f'label:update Label id:{db_label.id} for spec:{label} with sublabels:{sublabels}, parent_label:{parent_label}')
else:
logger.info(f'label:delete label:{label} with sublabels:{sublabels}, parent_label:{parent_label}')
if not label.get('deleted'): if not label.get('deleted'):
update_labels(sublabels, parent_label=db_label) update_labels(sublabels, parent_label=db_label)
if label.get('id') is None and db_label.type == str(models.LabelType.SKELETON): if label.get('id') is None and db_label.type == str(models.LabelType.SKELETON):
for db_sublabel in list(db_label.sublabels.all()): for db_sublabel in list(db_label.sublabels.all()):
svg = svg.replace(f'data-label-name="{db_sublabel.name}"', f'data-label-id="{db_sublabel.id}"') svg = svg.replace(f'data-label-name="{db_sublabel.name}"', f'data-label-id="{db_sublabel.id}"')
models.Skeleton.objects.create(root=db_label, svg=svg) db_skeleton = models.Skeleton.objects.create(root=db_label, svg=svg)
logger.info(f'label:update: Skeleton id:{db_skeleton.id} for label_id:{db_label.id}')
update_labels(labels) update_labels(labels)

Loading…
Cancel
Save