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:
|
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:
|
# 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.CASCADE so Teamware deletes all AnnotatorProject assignments for this project when the project is deleted, and/or
- perform checks in
rpc.delete_project and 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.
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:
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
AnnotatorProjectare set to simply set theprojectfield to NULL when the referencedProjectis deleted, rather than deleting the wholeAnnotatorProjectassignment:gate-teamware/backend/models.py
Lines 841 to 842 in 8b54bc1
This means that the user is not assigned to a project, but they are still considered as "active" in
rpc.get_possible_annotators:gate-teamware/backend/rpc.py
Lines 715 to 719 in 8b54bc1
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_annotatorprojecttable directly in the database to unblock them.Possible fixes
on_delete=models.CASCADEso Teamware deletes allAnnotatorProjectassignments for this project when the project is deleted, and/orrpc.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.