Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Should we have a layer that sends 4xx client errors for badly formed requests? #35

Open
hcientist opened this issue Oct 4, 2022 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@hcientist
Copy link
Contributor

So an unreasonable request (sending assignment_id as undefined) resulted in a server side error, but probably shouldn't?
I think this is where it got stuck:

return self.queryset.filter(assignment_id=self.kwargs["assignment_id"])

this is what happened:


Internal Server Error: /api/courses/6th-grade-band/assignments/undefined/submissions/
Traceback (most recent call last):
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 1823, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: 'undefined'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/rest_framework/mixins.py", line 38, in list
    queryset = self.filter_queryset(self.get_queryset())
  File "/Users/tgm/dev/CPR-Music-Backend/teleband/submissions/api/views.py", line 28, in get_queryset
    return self.queryset.filter(assignment_id=self.kwargs["assignment_id"])
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/query.py", line 941, in filter
    return self._filter_or_exclude(False, args, kwargs)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/query.py", line 961, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/query.py", line 968, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1393, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1412, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1347, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1193, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/lookups.py", line 25, in __init__
    self.rhs = self.get_prep_lookup()
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/fields/related_lookups.py", line 117, in get_prep_lookup
    self.rhs = target_field.get_prep_value(self.rhs)
  File "/Users/tgm/.pyenv/versions/CPR-Music-Backend/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 1825, in get_prep_value
    raise e.__class__(
ValueError: Field 'id' expected a number but got 'undefined'.
@hcientist hcientist added the bug Something isn't working label Oct 4, 2022
@hcientist hcientist added this to the F22 milestone Oct 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

1 participant