[Django] #31316: handler500 called multiple times

5 views
Skip to first unread message

Django

unread,
Feb 28, 2020, 3:56:47 AM2/28/20
to django-...@googlegroups.com
#31316: handler500 called multiple times
-----------------------------------------+------------------------
Reporter: David Szotten | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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)?

--
Ticket URL: <https://code.djangoproject.com/ticket/31316>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 2, 2020, 2:35:25 AM3/2/20
to django-...@googlegroups.com
#31316: handler500 called multiple times.
-------------------------------+--------------------------------------

Reporter: David Szotten | Owner: nobody
Type: Uncategorized | Status: closed
Component: HTTP handling | Version: master
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => invalid
* component: Uncategorized => HTTP handling


Comment:

`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).

--
Ticket URL: <https://code.djangoproject.com/ticket/31316#comment:1>

Django

unread,
Mar 2, 2020, 4:03:33 AM3/2/20
to django-...@googlegroups.com
#31316: handler500 called multiple times.
-------------------------------+--------------------------------------
Reporter: David Szotten | Owner: nobody
Type: Uncategorized | Status: closed
Component: HTTP handling | Version: master
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by David Szotten):

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)

--
Ticket URL: <https://code.djangoproject.com/ticket/31316#comment:2>

Django

unread,
Mar 2, 2020, 4:03:53 AM3/2/20
to django-...@googlegroups.com
#31316: handler500 called multiple times.
-------------------------------+--------------------------------------
Reporter: David Szotten | Owner: nobody
Type: Uncategorized | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by David Szotten):

* status: closed => new
* resolution: invalid =>


--
Ticket URL: <https://code.djangoproject.com/ticket/31316#comment:3>

Django

unread,
Mar 2, 2020, 6:15:28 AM3/2/20
to django-...@googlegroups.com
#31316: handler500 called multiple times.
-------------------------------+--------------------------------------
Reporter: David Szotten | Owner: nobody
Type: Uncategorized | Status: closed

Component: HTTP handling | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed

* resolution: => wontfix


Comment:

This is made by design (see
[https://github.com/django/django/blob/daaa894960e1b2bce8ee31b7c109be84f598a84e/django/core/handlers/base.py#L140-L149
process_exception_by_middleware()]), exceptions are processed by
middlewares (see
[https://docs.djangoproject.com/en/3.0/topics/http/middleware/#process-
exception #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.

--
Ticket URL: <https://code.djangoproject.com/ticket/31316#comment:4>

Reply all
Reply to author
Forward
0 new messages