Skip to content

Commit

Permalink
fix: LSDV-5367: Cancelled and updated annotations don't recalculate (H…
Browse files Browse the repository at this point in the history
…umanSignal#4472)

fix: LSDV-5367: Cancelled and updated annotations don't recalculate is_labeled and counters
  • Loading branch information
makseq authored Dec 19, 2023
1 parent f72e5aa commit 975fcb4
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions label_studio/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,16 +984,15 @@ def update_project_summary_annotations_and_is_labeled(sender, instance, created,
"""Update annotation counters in project summary"""
instance.increase_project_summary_counters()

if created:
# If new annotation created, update task.is_labeled state
logger.debug(f'Update task stats for task={instance.task}')
if instance.was_cancelled:
instance.task.cancelled_annotations = instance.task.annotations.all().filter(was_cancelled=True).count()
else:
instance.task.total_annotations = instance.task.annotations.all().filter(was_cancelled=False).count()
instance.task.update_is_labeled()
instance.task.save(update_fields=['is_labeled', 'total_annotations', 'cancelled_annotations'])
logger.debug(f'Updated total_annotations and cancelled_annotations for {instance.task.id}.')
# If annotation is changed, update task.is_labeled state
logger.debug(f'Update task stats for task={instance.task}')
if instance.was_cancelled:
instance.task.cancelled_annotations = instance.task.annotations.all().filter(was_cancelled=True).count()
else:
instance.task.total_annotations = instance.task.annotations.all().filter(was_cancelled=False).count()
instance.task.update_is_labeled()
instance.task.save(update_fields=['is_labeled', 'total_annotations', 'cancelled_annotations'])
logger.debug(f'Updated total_annotations and cancelled_annotations for {instance.task.id}.')


@receiver(pre_delete, sender=Prediction)
Expand Down

0 comments on commit 975fcb4

Please sign in to comment.