Opened 14 years ago

Closed 14 years ago

Last modified 8 years ago

#12594 closed (fixed)

Meaningless exception when DEBUG=False and resolver.urlconf_module is None.

Reported by: Yuri Baburov Owned by: Yuri Baburov
Component: HTTP handling Version: 1.2-alpha
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Because of resolver.resolve500() can now fail due to urlconf_module set to None in django/core/handlers/base.py,
sometimes site developer doesn't get appropriate error message.
Instead developer gets message that handler500 is not found in urlconf module.

Problem is only in handler500 lookup, everything else goes well.

How to reproduce:
set DEBUG to False, comment out ROOT_URLCONF line.

I managed to find this problem it another way, but it will take some time to figure out how settings.py can be imported without errors, but get empty dir to LazySettings.

My suggested fix:

    def handle_uncaught_exception(self, request, resolver, exc_info):
        ...
        mail_admins(subject, message, fail_silently=True)
        # Return an HttpResponse that displays a friendly error message.

        if resolver.urlconf_module is None: # FIX LINE1: you aren't getting http500!
            raise exc_info[1], None, exc_info[2] # FIX LINE2: so we'll raise it raw.

        callback, param_dict = resolver.resolve500()
        return callback(request, **param_dict)

Attachments (1)

12594.patch (3.0 KB ) - added by Yuri Baburov 14 years ago.
Patch with tests

Download all attachments as: .zip

Change History (11)

in reply to:  description comment:1 by Yuri Baburov, 14 years ago

Exception Before:

Traceback (most recent call last):

  File "/Projects/django/wn2/django/core/servers/basehttp.py", line 280, in run
    self.result = application(self.environ, self.start_response)

  File "/Projects/django/wn2/django/core/servers/basehttp.py", line 672, in __call__
    return self.application(environ, start_response)

  File "/Projects/django/wn2/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)

  File "/Projects/django/wn2/django/core/handlers/base.py", line 143, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)

  File "/Projects/django/wn2/django/core/handlers/base.py", line 180, in handle_uncaught_exception
    callback, param_dict = resolver.resolve500()

  File "/Projects/django/wn2/django/core/urlresolvers.py", line 269, in resolve500
    return self._resolve_special('500')

  File "/Projects/django/wn2/django/core/urlresolvers.py", line 259, in _resolve_special
    callback = getattr(self.urlconf_module, 'handler%s' % view_type)

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

Exception after:

Traceback (most recent call last):

  File "/Projects/django/wn2/django/core/servers/basehttp.py", line 280, in run
    self.result = application(self.environ, self.start_response)

  File "/Projects/django/wn2/django/core/servers/basehttp.py", line 672, in __call__
    return self.application(environ, start_response)

  File "/Projects/django/wn2/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)

  File "/Projects/django/wn2/django/core/handlers/base.py", line 143, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)

  File "/Projects/django/wn2/django/core/handlers/base.py", line 85, in get_response
    urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)

  File "/Projects/django/wn2/django/utils/functional.py", line 273, in __getattr__
    return getattr(self._wrapped, name)

AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'

comment:2 by Piotr Czachur, 14 years ago

I've met similar problems, when I got some internal error (I can give you further info if it's relevant) and django tried to display error page 500.
This problem occours *only* when settings.DEBUG is False.
When DEBUG is True I see helpful error page about actual error that have occoured, not error in error displaying :-)

Here you got Traceback, when DEBUG is FALSE:

    Traceback (most recent call last):

  File "/srv/trunk/external-packages/django/core/servers/basehttp.py", line 280, in run
    self.result = application(self.environ, self.start_response)

  File "/srv/trunk/external-packages/django/core/servers/basehttp.py", line 672, in __call__
    return self.application(environ, start_response)

  File "/srv/trunk/external-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)

  File "/srv/trunk/external-packages/django/core/handlers/base.py", line 143, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)

  File "/srv/trunk/external-packages/django/core/handlers/base.py", line 178, in handle_uncaught_exception
    callback, param_dict = resolver.resolve500()

  File "/srv/trunk/external-packages/django/core/urlresolvers.py", line 268, in resolve500
    return self._resolve_special('500')

  File "/srv/trunk/external-packages/django/core/urlresolvers.py", line 258, in _resolve_special
    callback = getattr(self.urlconf_module, 'handler%s' % view_type)

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

This message says nothing about actual error.

comment:3 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Karen Tracey, 14 years ago

Has patch: unset
Needs tests: set

Please attach a patch that is a diff, not an inline display of a complete routine.

comment:5 by Yuri Baburov, 14 years ago

Owner: changed from nobody to Yuri Baburov
Status: newassigned

I attached complete routine exactly because I wanted someone to write the patch and check me, I'm not sure in all python versions my re-raising exception works correctly.
Ok, going to attach test & patch tomorrow.

by Yuri Baburov, 14 years ago

Attachment: 12594.patch added

Patch with tests

comment:6 by Yuri Baburov, 14 years ago

Has patch: set
Needs tests: unset

Please check, mark RFC & commit.

comment:7 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: assignedclosed

(In [12854]) Fixed #12594 -- Ensured that a meaningful exception is raised when the urlconf_module is None. Thanks to buriy for the report and patch.

comment:8 by Russell Keith-Magee, 14 years ago

(In [12855]) [1.1.X] Fixed #12594 -- Ensured that a meaningful exception is raised when the urlconf_module is None. Thanks to buriy for the report and patch.

Backport of r12854 from trunk.

comment:9 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

comment:10 by GitHub <noreply@…>, 8 years ago

In 7e303d1:

Refs #12594 -- Removed obsolete exception handling in handle_uncaught_exception().

Since 859fc020a7c5ce30784d6388858ffbc613ef6612, this is no longer needed.

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