Opened 5 years ago

Closed 5 years ago

#31316 closed Uncategorized (wontfix)

handler500 called multiple times.

Reported by: David Szotten Owned by: nobody
Component: HTTP handling Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

i recently came across a situation where a (poorly designed) handler500 view ended up itself raising exceptions. i was slightly surprised to realise that the error handler ends up getting called once for each middleware. is this expected/desired (or e.g. just a side-effect of the current implementation)?

Change History (4)

comment:1 by Mariusz Felisiak, 5 years ago

Component: UncategorizedHTTP handling
Resolution: invalid
Status: newclosed
Summary: handler500 called multiple timeshandler500 called multiple times.

handler500 should return HttpResponseServerError, when it raises an exception then it's propagated to the next middleware and a custom handler is called again. This behavior is a side effect of an incorrect implementation of a custom handler500. It's called only once when returns HttpResponseServerError (as documented).

comment:2 by David Szotten, 5 years ago

apologies if i was being unclear. i acknowledge that the root cause was a bug in my 500 handler "(poorly designed)". however, my question was about how django should behave in the presence of such bugs. bugs are a fact of life, and for when they happen in regular view code, django provides the handler500 hook for custom error pages. it doesn't seem unreasonable that from time to time we also have bugs in our error handlers, and my question is how we want django to behave then. is the current behaviour of re-calling the handler500 once for each middleware desired in this case, or would we be interested in exploring other options? (or, perhaps it's not ideal but too rare to bother improving)

comment:3 by David Szotten, 5 years ago

Resolution: invalid
Status: closednew

comment:4 by Mariusz Felisiak, 5 years ago

Resolution: wontfix
Status: newclosed

This is made by design (see process_exception_by_middleware()), exceptions are processed by middlewares (see #process-exception), and a default exception handler (handler500) is used when process_exception() is not implemented. That's why your custom (buggy) handler is used by all middlewares. Your implementation doesn't follow documentation and I don't think there is anything to change in Django.

Note: See TracTickets for help on using tickets.
Back to Top