summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2010-03-22 19:16:31 +0000
committerKaren Tracey <kmtracey@gmail.com>2010-03-22 19:16:31 +0000
commitef41bd405e703f0881c4d6bc2c2a54146c965373 (patch)
treed8a72ba183150babab293686eb3a26f13bf52695
parentc2267602cb253868232d1ef49f3d1ab822f7b639 (diff)
[1.1.X] Fixed #12554 again: Corrected regression in silencing attribute lookups introduced in r12824, plus added a test for this so it doesn't regress again.
r12834 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12835 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/__init__.py5
-rw-r--r--tests/regressiontests/templates/tests.py8
2 files changed, 12 insertions, 1 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py
index b33ec0a0a8..2b8c998d1d 100644
--- a/django/template/__init__.py
+++ b/django/template/__init__.py
@@ -735,6 +735,11 @@ class Variable(object):
TypeError, # unsubscriptable object
):
raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute
+ except Exception, e:
+ if getattr(e, 'silent_variable_failure', False):
+ current = settings.TEMPLATE_STRING_IF_INVALID
+ else:
+ raise
except Exception, e:
if getattr(e, 'silent_variable_failure', False):
current = settings.TEMPLATE_STRING_IF_INVALID
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 6b7b1cef35..db5a3efa24 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -100,6 +100,11 @@ class SilentGetItemClass(object):
def __getitem__(self, key):
raise SomeException
+class SilentAttrClass(object):
+ def b(self):
+ raise SomeException
+ b = property(b)
+
class UTF8Class:
"Class whose __str__ returns non-ASCII data"
def __str__(self):
@@ -350,8 +355,9 @@ class Templates(unittest.TestCase):
# regression test for ticket #12554
# make sure a silent_variable_failure Exception is supressed
- # on dictionary lookup
+ # on dictionary and attribute lookup
'basic-syntax28': ("{{ a.b }}", {'a': SilentGetItemClass()}, ('', 'INVALID')),
+ 'basic-syntax29': ("{{ a.b }}", {'a': SilentAttrClass()}, ('', 'INVALID')),
# List-index syntax allows a template to access a certain item of a subscriptable object.
'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"),