Skip to content

Commit

Permalink
Fixed #16935 - misleading message if AttributeError escapes during Si…
Browse files Browse the repository at this point in the history
…mpleTemplateResponse.render

Thanks to isagalaev for the report.

As discussed on django-devs, this reverts some of the changes in [16568]
i.e.  the addition of `SimpleTemplateResponse.__getattr__`, because this
makes it much harder to debug the common case of an AttributeError somewhere
during the rendering of a SimpleTemplateResponse.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16917 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
lukeplant committed Sep 30, 2011
1 parent 44c09fe commit 6a946d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
12 changes: 0 additions & 12 deletions django/template/response.py
Expand Up @@ -6,10 +6,6 @@ class ContentNotRenderedError(Exception):
pass


class DiscardedAttributeError(AttributeError):
pass


class SimpleTemplateResponse(HttpResponse):
rendering_attrs = ['template_name', 'context_data', '_post_render_callbacks']

Expand All @@ -36,7 +32,6 @@ def __init__(self, template, context=None, mimetype=None, status=None,
# True, so we initialize it to False after the call to super __init__.
self._is_rendered = False


def __getstate__(self):
"""Pickling support function.
Expand All @@ -54,13 +49,6 @@ def __getstate__(self):

return obj_dict

def __getattr__(self, name):
if name in self.rendering_attrs:
raise DiscardedAttributeError('The %s attribute was discarded '
'when this %s class was pickled.' %
(name, self.__class__.__name__))
return super(SimpleTemplateResponse, self).__getattr__(name)

def resolve_template(self, template):
"Accepts a template object, path-to-template or list of paths"
if isinstance(template, (list, tuple)):
Expand Down
7 changes: 3 additions & 4 deletions tests/regressiontests/templates/response.py
Expand Up @@ -9,8 +9,7 @@
import django.template.context
from django.template import Template, Context
from django.template.response import (TemplateResponse, SimpleTemplateResponse,
ContentNotRenderedError,
DiscardedAttributeError)
ContentNotRenderedError)

def test_processor(request):
return {'processors': 'yes'}
Expand Down Expand Up @@ -198,7 +197,7 @@ def test_pickling(self):

# ...and requesting any of those attributes raises an exception
for attr in template_attrs:
with self.assertRaises(DiscardedAttributeError) as cm:
with self.assertRaises(AttributeError):
getattr(unpickled_response, attr)

def test_repickling(self):
Expand Down Expand Up @@ -282,7 +281,7 @@ def test_pickling(self):

# ...and requesting any of those attributes raises an exception
for attr in template_attrs:
with self.assertRaises(DiscardedAttributeError) as cm:
with self.assertRaises(AttributeError):
getattr(unpickled_response, attr)

def test_repickling(self):
Expand Down

0 comments on commit 6a946d4

Please sign in to comment.