Skip to content

Deleting a project with active annotators leaves those annotators ineligible to join another project #411

@ianroberts

Description

@ianroberts

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:

  1. Create a project
  2. Assign an annotator to that project
  3. Delete the project
  4. 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

  1. use on_delete=models.CASCADE so Teamware deletes all AnnotatorProject assignments for this project when the project is deleted, and/or
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions