Opened 3 weeks ago

Last modified 3 weeks ago

#36848 assigned Cleanup/optimization

Documentation doesn't directly mention that BadRequest is handled by handler400

Reported by: Lincoln Owned by: Lincoln
Component: Documentation Version: dev
Severity: Normal Keywords: handler400 bad_request
Cc: Lincoln Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A BadRequest exception raised in a view, is handled by the handler400 view (default django.views.defaults.bad_request).

https://github.com/django/django/blob/c68e4adea0703354508d51895b091771b1f6ac45/django/core/handlers/exception.py#L96-L104

Looking at the documentation, I can't see this link mentioned anywhere.

Places I looked:

For comparison, This section about the 404 view

https://docs.djangoproject.com/en/dev/ref/views/#the-404-page-not-found-view

explicitly says "When you raise Http404 from within a view, ..."

Change History (9)

comment:1 by Kundan Yadav, 3 weeks ago

Owner: set to Kundan Yadav
Status: newassigned

comment:2 by Natalia Bidart, 3 weeks ago

Keywords: handler400 bad_request added
Triage Stage: UnreviewedAccepted
Version: dev

Hello Lincoln! Thanks for the report.

While the current documentation already describes this behavior indirectly (the BadRequest exception docs says they resul in an HttpResponseBadRequest at the handler level with a status code of 400, and handler400 being responsible for rendering 400 responses), I agree that an explicit mention similar to Http404 would improve clarity. Accepting this as a small documentation clarification.

comment:3 by Natalia Bidart, 3 weeks ago

Kundan, just a quick suggestion regarding ticket assignments: while you are getting started with Django contributions, it is usually best to focus on one ticket at a time and see it through fully, including reviews and any required follow-ups, before taking on additional tickets. This helps keep tickets moving and avoids unintentionally blocking other contributors. Thanks! and I appreciate the interest in contributing.

comment:4 by Natalia Bidart, 3 weeks ago

Summary: Documentation doesn't mention that BadRequest is handled by handler400Documentation doesn't directly mention that BadRequest is handled by handler400

comment:5 by Kundan Yadav, 3 weeks ago

i am sorry again i will keep all this in my mind am really sorry again

comment:6 by Lincoln, 3 weeks ago

Thanks Natalia for the quick reply.

To me (someone not familiar with Django internals) its not obvious what the part about "reaches the ASGI/WSGI handler level" in BadRequest docs means.

The part "results in a HttpResponseBadRequest." is ambiguous to me, that could be a 400 response with no body.

The handler400 docs say "the view that should be called if the HTTP client has sent a request that caused an error condition and a response with a status code of 400."

This is also ambiguous to me. For example a view that manually returns a 400 response, does NOT trigger this handler, when you could interpret it to mean that.

comment:7 by Lincoln, 3 weeks ago

I am happy to provide a PR, since I am the one complaining

in reply to:  7 comment:8 by Natalia Bidart, 3 weeks ago

Replying to Lincoln:

I am happy to provide a PR, since I am the one complaining

Amazing, thank you Lincoln! I'll switch ownership to you, following my conversation with Kundan.

comment:9 by Natalia Bidart, 3 weeks ago

Owner: changed from Kundan Yadav to Lincoln
Note: See TracTickets for help on using tickets.
Back to Top