Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#13684 closed Bug (fixed)

a bug in a catch-all try..except in Django masks other exceptions: local variable 'resolver' referenced before assignment

Reported by: Antti Kaihola Owned by: nobody
Component: HTTP handling Version: 1.3
Severity: Normal Keywords:
Cc: techtonik@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I ran into this when my custom settings for running unit tests didn't include ROOT_URLCONF, and others have seen this too
(1,
2,
3).

In django.core.handlers.base.get_response, the resolver variable is defined inside a try: block and referenced in the final catch-all except: block. I'd move setting up the default url resolver outside the try..except block since a problem there probably prevents rendering 500 pages.

Attachments (3)

13684_local_variable_resolver.1.diff (945 bytes ) - added by Antti Kaihola 14 years ago.
moves default url resolver setup outside try..except
django-core-handlers-base-1.diff (910 bytes ) - added by brendoncrawford 14 years ago.
django-core-handlers-base-2.diff (1.0 KB ) - added by sbc 14 years ago.
updating to apply to head

Download all attachments as: .zip

Change History (12)

by Antti Kaihola, 14 years ago

moves default url resolver setup outside try..except

comment:1 by Antti Kaihola, 14 years ago

Here's the traceback I got before applying the patch:

Traceback (most recent call last):
  File "myapp/tests.py", line 14, in test_example
    self.client.post('/', {})
  File "django/django/django/test/client.py", line 322, in post
    response = self.request(**r)
  File "django/django/django/test/client.py", line 230, in request
    response = self.handler(environ)
  File "django/django/django/test/client.py", line 74, in __call__
    response = self.get_response(request)
  File "django/django/django/core/handlers/base.py", line 142, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)
UnboundLocalError: local variable 'resolver' referenced before assignment

This is the proper traceback after applying the patch:

Traceback (most recent call last):
  File "myapp/tests.py", line 14, in test_example
    self.client.post('/', {})
  File "django/django/django/test/client.py", line 322, in post
    response = self.request(**r)
  File "django/django/django/test/client.py", line 230, in request
    response = self.handler(environ)
  File "django/django/django/test/client.py", line 74, in __call__
    response = self.get_response(request)
  File "django/django/django/core/handlers/base.py", line 73, in get_response
    urlconf = settings.ROOT_URLCONF
  File "django/django/django/utils/functional.py", line 277, in __getattr__
    return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'

comment:2 by Antti Kaihola, 14 years ago

Summary: Django bug masks real errors: local variable 'resolver' referenced before assignmenta bug in a catch-all try..except in Django masks other exceptions: local variable 'resolver' referenced before assignment

by brendoncrawford, 14 years ago

comment:3 by brendoncrawford, 14 years ago

The first patch does not work for me. I have attached a patch above that works for me.

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

milestone: 1.3
Triage Stage: UnreviewedAccepted

by sbc, 14 years ago

updating to apply to head

comment:5 by Alex Gaynor, 14 years ago

Resolution: fixed
Status: newclosed

(In [14488]) Fixed #13684 -- if settings.ROOT_URLCONF isn't defined don't blow up with an UnboundLocalError.

comment:6 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

comment:7 by anatoly techtonik <techtonik@…>, 13 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

In which version it is fixed?

comment:8 by anatoly techtonik <techtonik@…>, 13 years ago

Cc: techtonik@… added

comment:9 by anatoly techtonik <techtonik@…>, 13 years ago

Type: UncategorizedBug
Version: SVN1.3

Fixed in Django 1.3. Not backported to 1.2

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