Skip to content

Commit

Permalink
fix: DIA-783: Fix adding candidate task if it was accidentally delete…
Browse files Browse the repository at this point in the history
…d from project (#5222)

* fix: DIA-783: Fix adding candidate task if it was accidentally deleted from the project
  • Loading branch information
KonstantinKorotaev authored Dec 28, 2023
1 parent 875adaf commit 2e3106d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions label_studio/data_manager/actions/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def delete_tasks(project, queryset, **kwargs):
project.views.all().delete()
reload = True

# Execute actions after delete tasks
Task.after_bulk_delete_actions(tasks_ids_list)

return {'processed_items': count, 'reload': reload, 'detail': 'Deleted ' + str(count) + ' tasks'}


Expand Down
13 changes: 13 additions & 0 deletions label_studio/tasks/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ def update_is_labeled(self, *args, **kwargs) -> None:
def post_process_bulk_update_stats(cls, tasks) -> None:
pass

def before_delete_actions(self):
"""
Actions to execute before task deletion
"""
pass

@staticmethod
def after_bulk_delete_actions(tasks_ids):
"""
Actions to execute after bulk task deletion
"""
pass


class AnnotationMixin:
def has_permission(self, user: 'User') -> bool: # noqa: F821
Expand Down
6 changes: 6 additions & 0 deletions label_studio/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ def delete_tasks_without_signals_from_task_ids(task_ids):
queryset = Task.objects.filter(id__in=task_ids)
Task.delete_tasks_without_signals(queryset)

def delete(self, *args, **kwargs):
self.before_delete_actions()
result = super().delete(*args, **kwargs)
# set updated_at field of task to now()
return result


pre_bulk_create = Signal(providing_args=['objs', 'batch_size'])
post_bulk_create = Signal(providing_args=['objs', 'batch_size'])
Expand Down

0 comments on commit 2e3106d

Please sign in to comment.