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 548eac6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions tin/apps/submissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import psutil
from django import http
from django.db.models import F, Q
from django.db.models import F
from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone
from django.utils.http import url_has_allowed_host_and_scheme
Expand Down 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 548eac6

Please sign in to comment.