-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Describe the bug
If an "in-progress" annotation project is deleted, any active annotator users who are assigned to that project are left permanently ineligible to be assigned to any other projects.
To Reproduce
Steps to reproduce the behavior:
- Create a project
- Assign an annotator to that project
- Delete the project
- Attempt to assign the same annotator to a different project - they are not listed in the eligible annotators list
Expected behavior
Deleting a project should free up the annotators who were assigned to that project to be able to annotate other projects.
Additional context
The root cause of this problem appears to be that the foreign key constraints on AnnotatorProject are set to simply set the project field to NULL when the referenced Project is deleted, rather than deleting the whole AnnotatorProject assignment:
gate-teamware/backend/models.py
Lines 841 to 842 in 8b54bc1
| annotator = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True, blank=True) | |
| project = models.ForeignKey(Project, on_delete=models.SET_NULL, null=True, blank=True) |
This means that the user is not assigned to a project, but they are still considered as "active" in rpc.get_possible_annotators:
Lines 715 to 719 in 8b54bc1
| # get a list of IDs of annotators that is currently active in any project | |
| active_annotators = User.objects.filter(annotatorproject__status=AnnotatorProject.ACTIVE).values_list('id', flat=True) | |
| project_annotators = project.annotators.all().values_list('id', flat=True) | |
| # Do an exclude filter to remove annotator with the those ids | |
| valid_annotators = User.objects.filter(is_deleted=False).exclude(id__in=active_annotators).exclude(id__in=project_annotators) |
and thus not available to be assigned to any other project. When this happened to @iabufarha in production I had to delete the offending row from the backend_annotatorproject table directly in the database to unblock them.
Possible fixes
- use
on_delete=models.CASCADEso Teamware deletes allAnnotatorProjectassignments for this project when the project is deleted, and/or - perform checks in
rpc.delete_projectand disallow deletion of a project that has active annotators. The manager would need to mark all annotators as "complete" or "rejected" before being allowed to delete the project.