Skip to content

Commit

Permalink
[1.1.X] Fixed #12554 again: Corrected regression in silencing attribu…
Browse files Browse the repository at this point in the history
…te 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
  • Loading branch information
kmtracey committed Mar 22, 2010
1 parent c226760 commit ef41bd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions django/template/__init__.py
Expand Up @@ -735,6 +735,11 @@ def _resolve_lookup(self, context):
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
Expand Down
8 changes: 7 additions & 1 deletion tests/regressiontests/templates/tests.py
Expand Up @@ -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):
Expand Down Expand Up @@ -350,8 +355,9 @@ def get_template_tests(self):

# 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"),
Expand Down

0 comments on commit ef41bd4

Please sign in to comment.