Opened 10 years ago
Closed 10 years ago
#23070 closed Bug (fixed)
Instances of callable classes with __slots__ attributes in settings causes a failure to draw the 500 template
Reported by: | colons | Owned by: | Hiroki Kiyohara |
---|---|---|---|
Component: | Core (Other) | Version: | 1.7-rc-1 |
Severity: | Release blocker | Keywords: | |
Cc: | Baptiste Mispelon, hirokiky@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In a fresh django project, adding the following snippet to your settings files prevents the 500 page from rendering:
class Class(object): __slots__ = ['attr'] def __init__(self, attr): self.attr = attr def __call__(self): pass INSTANCE = Class(1)
The error that prevents the 500 error page from rendering is:
Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run self.result = application(self.environ, self.start_response) File "venv/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__ return self.application(environ, start_response) File "venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 191, in __call__ response = self.get_response(request) File "venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 198, in get_response response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) File "venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 241, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "venv/lib/python2.7/site-packages/django/views/debug.py", line 79, in technical_500_response html = reporter.get_traceback_html() File "venv/lib/python2.7/site-packages/django/views/debug.py", line 337, in get_traceback_html c = Context(self.get_traceback_data(), use_l10n=False) File "venv/lib/python2.7/site-packages/django/views/debug.py", line 315, in get_traceback_data 'settings': get_safe_settings(), File "venv/lib/python2.7/site-packages/django/views/debug.py", line 65, in get_safe_settings settings_dict[k] = cleanse_setting(k, getattr(settings, k)) File "venv/lib/python2.7/site-packages/django/views/debug.py", line 55, in cleanse_setting cleansed.do_not_call_in_templates = True AttributeError: 'Class' object has no attribute 'do_not_call_in_templates
For me, this is a problem because I'm upgrading a project that stores what time of the week certain things happen with instances of dateutil's weekday object in the settings. Reproduced in 1.7c1 and current master, never happened in 1.6. I can probably work around it, but it'll be upsettingly inelegant.
Attachments (5)
Change History (14)
by , 10 years ago
Attachment: | do_not_call.zip added |
---|
comment:1 by , 10 years ago
Could you bisect Django's history to the commit that introduced the change?
comment:2 by , 10 years ago
https://github.com/django/django/commit/3c5cdaf47aae7e4f21398be1a5eaa07f7c5ce31c
Would it be unreasonable to have cleanse_setting return a repr() or a str() (or unicode()) of the settings rather than the things themselves? That way it has direct control over whether or not they are called and doesn't have to rely on attempting to set attributes on objects that could be a type for all it knows.
comment:3 by , 10 years ago
Any object that cannot have the 'do_not_call_in_templates' attribute set on being set in settings will cause this issue, by the way; you can also cause it by using types or exceptions::
SCORE_NUMBER_TYPE = int PASSABLE_EXCEPTION = ValueError
comment:4 by , 10 years ago
Cc: | added |
---|---|
Component: | Uncategorized → Core (Other) |
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
CCing Baptiste since he committed the change. Perhaps he can offer guidance.
by , 10 years ago
Attachment: | 23070.diff added |
---|
comment:6 by , 10 years ago
Cc: | added |
---|---|
Has patch: | set |
I added patch to solve it.
On this change it solve by using force_text
instead of adding do_not_call_in_template
.
And also I added screen shots when the patch is applied.
comment:7 by , 10 years ago
Patch needs improvement: | set |
---|
This means that the debug page gives the wrong information (ADDED_CALLABLE
is a function object but the page says it's a string).
We need to find a different approach.
comment:8 by , 10 years ago
Patch needs improvement: | unset |
---|
@bmispelon Thanks for the review
I fixed it and sent pull-request https://github.com/django/django/pull/2967.
Now the setting value appearing the debug page is valid.
by , 10 years ago
Attachment: | 23070_2.png added |
---|
comment:9 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
A project that exhibits this bug.