Skip to content

Commit

Permalink
Hotfix: Fix invalid query when killing submissions
Browse files Browse the repository at this point in the history
This fixes the below production error:
```
  File ".../tin/tin/apps/submissions/views.py", line 106, in kill_view
    submission = get_object_or_404(submissions_editable, id=submission_id)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/django/shortcuts.py", line 85, in get_object_or_404
    return queryset.get(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../site-packages/django/db/models/query.py", line 640, in get
    raise self.model.MultipleObjectsReturned(
tin.apps.submissions.models.Submission.MultipleObjectsReturned: get() returned more than one Submission -- it returned 5!
```

One solution would have been to append a `.distinct()` to the query, but instead it was replaced by `filter_visible()` for consistency.
  • Loading branch information
krishnans2006 committed Jan 8, 2025
1 parent 9e906c1 commit feec15e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tin/apps/submissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ def kill_view(request, submission_id):
request: The request
submission_id: An instance of the :class:`.Submission` model
"""
submissions_editable = Submission.objects.filter(
Q(assignment__course__teacher=request.user) | Q(student=request.user)
submission = get_object_or_404(
Submission.objects.filter_visible(request.user), id=submission_id
)
submission = get_object_or_404(submissions_editable, id=submission_id)

if request.method == "POST":
submission.kill_requested = True
Expand Down

0 comments on commit feec15e

Please sign in to comment.