File: api/leaderboard/views.py
Line: 657
Problem:
The delete method on UserTasksManage catches UserTasks.DoesNotExist instead of User.DoesNotExist when trying to look up the user:
# Line 655-660
def delete(self, request, *args, **kwargs):
try:
user = User.objects.get(username=request.data["username"])
except UserTasks.DoesNotExist: # WRONG: should be User.DoesNotExist
return Response(
{"error": "User Not Found"}, status=status.HTTP_404_NOT_FOUND
)
If the user doesn't exist, a User.DoesNotExist exception is raised but NOT caught, causing an unhandled 500 error. The caught exception type (UserTasks.DoesNotExist) never occurs at this location.
Impact: Deleting tasks for non-existent users crashes the API with a 500 server error instead of returning a proper 404 response.
Fix: Change line 657 to except User.DoesNotExist:
File:
api/leaderboard/views.pyLine: 657
Problem:
The
deletemethod onUserTasksManagecatchesUserTasks.DoesNotExistinstead ofUser.DoesNotExistwhen trying to look up the user:If the user doesn't exist, a
User.DoesNotExistexception is raised but NOT caught, causing an unhandled 500 error. The caught exception type (UserTasks.DoesNotExist) never occurs at this location.Impact: Deleting tasks for non-existent users crashes the API with a 500 server error instead of returning a proper 404 response.
Fix: Change line 657 to
except User.DoesNotExist: