Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16935 - misleading message if AttributeError escapes during Si…

…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...
commit 6a946d4df5d588c7f62f1d2878e8577386c5ba0a 1 parent 44c09fe
lukeplant authored
12 django/template/response.py
@@ -6,10 +6,6 @@ class ContentNotRenderedError(Exception):
6 6 pass
7 7
8 8
9   -class DiscardedAttributeError(AttributeError):
10   - pass
11   -
12   -
13 9 class SimpleTemplateResponse(HttpResponse):
14 10 rendering_attrs = ['template_name', 'context_data', '_post_render_callbacks']
15 11
@@ -36,7 +32,6 @@ def __init__(self, template, context=None, mimetype=None, status=None,
36 32 # True, so we initialize it to False after the call to super __init__.
37 33 self._is_rendered = False
38 34
39   -
40 35 def __getstate__(self):
41 36 """Pickling support function.
42 37
@@ -54,13 +49,6 @@ def __getstate__(self):
54 49
55 50 return obj_dict
56 51
57   - def __getattr__(self, name):
58   - if name in self.rendering_attrs:
59   - raise DiscardedAttributeError('The %s attribute was discarded '
60   - 'when this %s class was pickled.' %
61   - (name, self.__class__.__name__))
62   - return super(SimpleTemplateResponse, self).__getattr__(name)
63   -
64 52 def resolve_template(self, template):
65 53 "Accepts a template object, path-to-template or list of paths"
66 54 if isinstance(template, (list, tuple)):
7 tests/regressiontests/templates/response.py
@@ -9,8 +9,7 @@
9 9 import django.template.context
10 10 from django.template import Template, Context
11 11 from django.template.response import (TemplateResponse, SimpleTemplateResponse,
12   - ContentNotRenderedError,
13   - DiscardedAttributeError)
  12 + ContentNotRenderedError)
14 13
15 14 def test_processor(request):
16 15 return {'processors': 'yes'}
@@ -198,7 +197,7 @@ def test_pickling(self):
198 197
199 198 # ...and requesting any of those attributes raises an exception
200 199 for attr in template_attrs:
201   - with self.assertRaises(DiscardedAttributeError) as cm:
  200 + with self.assertRaises(AttributeError):
202 201 getattr(unpickled_response, attr)
203 202
204 203 def test_repickling(self):
@@ -282,7 +281,7 @@ def test_pickling(self):
282 281
283 282 # ...and requesting any of those attributes raises an exception
284 283 for attr in template_attrs:
285   - with self.assertRaises(DiscardedAttributeError) as cm:
  284 + with self.assertRaises(AttributeError):
286 285 getattr(unpickled_response, attr)
287 286
288 287 def test_repickling(self):

0 comments on commit 6a946d4

Please sign in to comment.
Something went wrong with that request. Please try again.