Skip to content

Commit

Permalink
fix: DIA-1419: RunTime error occurs on trying to delete certain promp…
Browse files Browse the repository at this point in the history
…ts (#6374)

Co-authored-by: nik <nik@heartex.net>
  • Loading branch information
niklub and nik authored Sep 12, 2024
1 parent 3ac5730 commit b7eb5f0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions label_studio/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,9 +1291,23 @@ def remove_predictions_from_project(sender, instance, **kwargs):
"""Remove predictions counters"""
instance.task.total_predictions = instance.task.predictions.all().count() - 1
instance.task.save(update_fields=['total_predictions'])

# if there is PredictionMeta object associated with the Prediction object, delete it
if hasattr(instance, 'meta'):
logger.debug(f'Deleting PredictionMeta object associated with Prediction object {instance.id}')
instance.meta.delete()

logger.debug(f'Updated total_predictions for {instance.task.id}.')


@receiver(pre_delete, sender=FailedPrediction)
def remove_failed_predictions_from_project(sender, instance, **kwargs):
# if there is PredictionMeta object associated with the Prediction object, delete it
if hasattr(instance, 'meta'):
logger.debug(f'Deleting PredictionMeta object associated with Prediction object {instance.id}')
instance.meta.delete()


@receiver(post_save, sender=Prediction)
def save_predictions_to_project(sender, instance, **kwargs):
"""Add predictions counters"""
Expand Down

0 comments on commit b7eb5f0

Please sign in to comment.