#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)
Change History (12)
by , 15 years ago
| Attachment: | 13684_local_variable_resolver.1.diff added |
|---|
comment:1 by , 15 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 , 15 years ago
| Summary: | Django bug masks real errors: local variable 'resolver' referenced before assignment → a bug in a catch-all try..except in Django masks other exceptions: local variable 'resolver' referenced before assignment |
|---|
by , 15 years ago
| Attachment: | django-core-handlers-base-1.diff added |
|---|
comment:3 by , 15 years ago
The first patch does not work for me. I have attached a patch above that works for me.
comment:4 by , 15 years ago
| milestone: | → 1.3 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:5 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:7 by , 14 years ago
| Easy pickings: | unset |
|---|---|
| Severity: | → Normal |
| Type: | → Uncategorized |
| UI/UX: | unset |
In which version it is fixed?
comment:8 by , 14 years ago
| Cc: | added |
|---|
comment:9 by , 14 years ago
| Type: | Uncategorized → Bug |
|---|---|
| Version: | SVN → 1.3 |
Fixed in Django 1.3. Not backported to 1.2
moves default url resolver setup outside try..except