Skip to content

Could not delete competition #921

Closed
Closed

Description

@Didayolo

When trying to remove this competition (as the primary organizer of the competition), we obtain the following error.

https://www.codabench.org/competitions/1002/?secret_key=5781b096-f6a8-49a4-970a-f0f05a3a5d3b

Capture d’écran 2023-06-09 à 11 41 03

Here is the Django error logs on the platform:

django_1          | Internal Server Error: /api/competitions/1002/
django_1          | Traceback (most recent call last):
django_1          |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
django_1          |     response = get_response(request)
django_1          |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
django_1          |     response = self.process_exception_by_middleware(e, request)
django_1          |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
django_1          |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
django_1          |   File "/usr/local/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
django_1          |     return view_func(*args, **kwargs)
django_1          |   File "/usr/local/lib/python3.8/site-packages/rest_framework/viewsets.py", line 116, in view
django_1          |     return self.dispatch(request, *args, **kwargs)
django_1          |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 495, in dispatch
django_1          |     response = self.handle_exception(exc)
django_1          |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 455, in handle_exception
django_1          |     self.raise_uncaught_exception(exc)
django_1          |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 492, in dispatch
django_1          |     response = handler(request, *args, **kwargs)
django_1          |   File "/app/src/apps/api/views/competitions.py", line 224, in destroy
django_1          |     return super().destroy(request, *args, **kwargs)
django_1          |   File "/usr/local/lib/python3.8/site-packages/rest_framework/mixins.py", line 93, in destroy
django_1          |     self.perform_destroy(instance)
django_1          |   File "/usr/local/lib/python3.8/site-packages/rest_framework/mixins.py", line 97, in perform_destroy
django_1          |     instance.delete()
django_1          |   File "/app/src/apps/chahub/models.py", line 143, in delete
django_1          |     super().delete(*args, **kwargs)
django_1          |   File "/usr/local/lib/python3.8/site-packages/django/db/models/base.py", line 921, in delete
django_1          |     collector.collect([self], keep_parents=keep_parents)
django_1          |   File "/usr/local/lib/python3.8/site-packages/django/db/models/deletion.py", line 224, in collect
django_1          |     field.remote_field.on_delete(self, field, sub_objs, self.using)
django_1          |   File "/usr/local/lib/python3.8/site-packages/django/db/models/deletion.py", line 22, in PROTECT
django_1          |     raise ProtectedError(
django_1          | django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'Competition' because they are referenced through a protected foreign key: 'Data.competition'", <QuerySet [<Data: fnachalearn - submission(15789)>, <Data: fnachalearn - submission(15790)>]>)

I've seen that the organizer was in status "denied" from the competition, but even when approved the bug remains.

Capture d’écran 2023-06-09 à 11 46 44

I think this log describe the problem:

django_1          | django.db.models.deletion.ProtectedError: ("Cannot delete some instances of model 'Competition' because they are referenced through a protected foreign key: 'Data.competition'", <QuerySet [<Data: fnachalearn - submission(15789)>, <Data: fnachalearn - submission(15790)>]>)

Activity

  1. Didayolo commented on Jun 9, 2023

    @Didayolo
    MemberAuthor

    For more context, the "error comp" cannot be deleted after the organizer deleted his submissions by checking the box and select Delete submissions as below:

    Screenshot 2023-06-09 at 11 52 33 AM

    instead of clicking the red bin:

    Screenshot 2023-06-09 at 11 50 50 AM
  2. ihsaan-ullah commented on Jun 9, 2023

    @ihsaan-ullah
    Collaborator

    Trying to reproduce this

    1. New competition without any submission -> Deleted successfully
    2. New competition with one submission uploaded -> Deletion failed

    I think this problem is there because of new addition to data model here:
    https://github.com/codalab/codabench/blob/f55e5ccd15027a29a6068e46ae23cf977e231446/src/apps/datasets/models.py#LL61C12-L61C12

    changing models.PROTECT to models. CASCADE will solve the problem

  3. Didayolo commented on Jun 9, 2023

    @Didayolo
    MemberAuthor

    @ihsaan-ullah wow you are getting quicker to fix issues everyday!

    I think our automatic tests should have catch this issue. We should add a "delete competition" test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions