Fixed #12554 again: Corrected regression in silencing attribute lookups introduced in r12823, plus added a test for this so it doesn't regress again.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12834 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b2db1b24c6
commit
ed36a5f2ce
|
@ -745,6 +745,11 @@ class Variable(object):
|
||||||
TypeError, # unsubscriptable object
|
TypeError, # unsubscriptable object
|
||||||
):
|
):
|
||||||
raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute
|
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:
|
except Exception, e:
|
||||||
if getattr(e, 'silent_variable_failure', False):
|
if getattr(e, 'silent_variable_failure', False):
|
||||||
current = settings.TEMPLATE_STRING_IF_INVALID
|
current = settings.TEMPLATE_STRING_IF_INVALID
|
||||||
|
|
|
@ -101,6 +101,11 @@ class SilentGetItemClass(object):
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
raise SomeException
|
raise SomeException
|
||||||
|
|
||||||
|
class SilentAttrClass(object):
|
||||||
|
def b(self):
|
||||||
|
raise SomeException
|
||||||
|
b = property(b)
|
||||||
|
|
||||||
class UTF8Class:
|
class UTF8Class:
|
||||||
"Class whose __str__ returns non-ASCII data"
|
"Class whose __str__ returns non-ASCII data"
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -471,8 +476,9 @@ class Templates(unittest.TestCase):
|
||||||
|
|
||||||
# regression test for ticket #12554
|
# regression test for ticket #12554
|
||||||
# make sure a silent_variable_failure Exception is supressed
|
# 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-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-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"),
|
'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"),
|
||||||
|
|
Loading…
Reference in New Issue