#35098: ValidationError is being converted into a 500 Internal Server Error
response
-----------------------------------+--------------------------------------
Reporter: Yawar Quadir Amin | Owner: (none)
Type: Bug | Status: closed
Component: Error reporting | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------------+--------------------------------------
Comment (by Yawar Quadir Amin):
Here's a simplified example. I have a `views.py` with:
{{{
# Obviously, this is used as a handler for a route in urls.py
def handle_foo(request: HttpRequest, **kwargs: dict[str, Any]) ->
HttpResponse:
do_something(json.loads(request.body.decode('utf-8'))['field_i_want'])
}}}
And I have `do_something` defined as:
{{{
def do_something(value: str):
if bad(value): raise ValidationError('bad value')
return f'good value: {value}'
}}}
Now I expect this to respond with a 400 Bad Request, but it responds with
500 Internal Server Error. And the traceback points to the function in
Django Core which I linked earlier. It seems like this function is
supposed to handle Django exceptions, so I'm wondering why it doesn't
handle the ValidationException?
--
Ticket URL: <https://code.djangoproject.com/ticket/35098#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018cefdc6389-c2cd2122-4725-41fb-992d-31bfa659987e-000000%40eu-central-1.amazonses.com.