Opened 6 years ago

Closed 6 years ago

#13090 closed (fixed)

Incorrect handling of middleware exceptions

Reported by: EroSennin Owned by: isagalaev
Component: HTTP handling Version: master
Severity: Keywords:
Cc: EroSennin Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Django won't display a 500 error page with DEBUG=False if an exception is raised from a middleware. The following traceback is returned instead:

Traceback (most recent call last):

  File "/home/erosennin/workspace/ipi/django/trunk/django/core/servers/", line 280, in run
    self.result = application(self.environ, self.start_response)

  File "/home/erosennin/workspace/ipi/django/trunk/django/core/servers/", line 674, in __call__
    return self.application(environ, start_response)

  File "/home/erosennin/workspace/ipi/django/trunk/django/core/handlers/", line 241, in __call__
    response = self.get_response(request)

  File "/home/erosennin/workspace/ipi/django/trunk/django/core/handlers/", line 143, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)

  File "/home/erosennin/workspace/ipi/django/trunk/django/core/handlers/", line 178, in handle_uncaught_exception
    callback, param_dict = resolver.resolve500()

  File "/home/erosennin/workspace/ipi/django/trunk/django/core/", line 268, in resolve500
    return self._resolve_special('500')

  File "/home/erosennin/workspace/ipi/django/trunk/django/core/", line 258, in _resolve_special
    callback = getattr(self.urlconf_module, 'handler%s' % view_type)

AttributeError: 'NoneType' object has no attribute 'handler500'

This problem has been fixed in [12165], then reintroduced in [12186].

See also #6094.

Attachments (2)

13090.diff (1.8 KB) - added by isagalaev 6 years ago.
13090.1.diff (3.7 KB) - added by isagalaev 6 years ago.
Patch with tests

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by isagalaev

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to isagalaev
  • Patch needs improvement unset

Huh... We've found the same bug just yesterday. I'll try to fix this tomorrow since both commits is my code.

comment:2 Changed 6 years ago by isagalaev

P.S. EroSennin, and the separate bug report with a traceback is indeed helpful.

Changed 6 years ago by isagalaev


comment:3 Changed 6 years ago by isagalaev

  • Has patch set

Attached patch fixes the issue in what I believe a clean way. There's no test since the bug only occurs under DEBUG=False and AFAIK tests always run under DEBUG=True.

Changed 6 years ago by isagalaev

Patch with tests

comment:4 Changed 6 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [12773]) Fixed #13090 -- Corrected handling of errors in middleware when DEBUG=False. Thanks to EroSennin for the report, and Ivan Sagalaev for the patch.

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