[Django] #23070: Instances of callable classes with __slots__ attributes in settings causes a failure to draw the 500 template

6 views
Skip to first unread message

Django

unread,
Jul 21, 2014, 6:37:18 PM7/21/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
-------------------------------+----------------------
Reporter: colons | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.7-rc-1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+----------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23070>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 22, 2014, 7:10:24 PM7/22/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
-------------------------------+--------------------------------------

Reporter: colons | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Could you bisect Django's history to the commit that introduced the
change?

--
Ticket URL: <https://code.djangoproject.com/ticket/23070#comment:1>

Django

unread,
Jul 23, 2014, 2:50:00 AM7/23/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
-------------------------------+--------------------------------------

Reporter: colons | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by anonymous):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23070#comment:2>

Django

unread,
Jul 23, 2014, 4:09:09 AM7/23/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
-------------------------------+--------------------------------------

Reporter: colons | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.7-rc-1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by anonymous):

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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23070#comment:3>

Django

unread,
Jul 23, 2014, 8:36:33 PM7/23/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
---------------------------------+------------------------------------

Reporter: colons | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.7-rc-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by timo):

* cc: bmispelon (added)
* component: Uncategorized => Core (Other)
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

CCing Baptiste since he committed the change. Perhaps he can offer
guidance.

--
Ticket URL: <https://code.djangoproject.com/ticket/23070#comment:4>

Django

unread,
Jul 26, 2014, 4:14:51 AM7/26/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
---------------------------------+------------------------------------
Reporter: colons | Owner: hirokiky
Type: Bug | Status: assigned

Component: Core (Other) | Version: 1.7-rc-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by hirokiky):

* status: new => assigned
* owner: nobody => hirokiky


Comment:

trying

--
Ticket URL: <https://code.djangoproject.com/ticket/23070#comment:5>

Django

unread,
Jul 26, 2014, 4:36:59 AM7/26/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
---------------------------------+------------------------------------
Reporter: colons | Owner: hirokiky
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.7-rc-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by hirokiky):

* cc: hirokiky@… (added)
* has_patch: 0 => 1


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23070#comment:6>

Django

unread,
Jul 26, 2014, 5:14:05 AM7/26/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
---------------------------------+------------------------------------
Reporter: colons | Owner: hirokiky
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.7-rc-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by bmispelon):

* needs_better_patch: 0 => 1


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23070#comment:7>

Django

unread,
Jul 26, 2014, 6:44:30 AM7/26/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
---------------------------------+------------------------------------
Reporter: colons | Owner: hirokiky
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.7-rc-1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by hirokiky):

* needs_better_patch: 1 => 0


Comment:

@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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23070#comment:8>

Django

unread,
Jul 26, 2014, 8:39:40 AM7/26/14
to django-...@googlegroups.com
#23070: Instances of callable classes with __slots__ attributes in settings causes
a failure to draw the 500 template
---------------------------------+------------------------------------
Reporter: colons | Owner: hirokiky
Type: Bug | Status: closed

Component: Core (Other) | Version: 1.7-rc-1
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by James Bennett <james@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"63058786882f6a32649a0fdafae9cb425c95cd4e"]:
{{{
#!CommitTicketReference repository=""
revision="63058786882f6a32649a0fdafae9cb425c95cd4e"
Merge pull request #2967 from hirokiky/fix23070

Fixed #23070 -- not to break the debug page by callable setting with
__slots__
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23070#comment:9>

Reply all
Reply to author
Forward
0 new messages