Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #12554 again: Corrected regression in silencing attribu…

…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...
commit ef41bd405e703f0881c4d6bc2c2a54146c965373 1 parent c226760
Karen Tracey authored March 22, 2010
5  django/template/__init__.py
@@ -735,6 +735,11 @@ def _resolve_lookup(self, context):
735 735
                             TypeError,  # unsubscriptable object
736 736
                             ):
737 737
                         raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute
  738
+                except Exception, e:
  739
+                    if getattr(e, 'silent_variable_failure', False):
  740
+                        current = settings.TEMPLATE_STRING_IF_INVALID
  741
+                    else:
  742
+                        raise
738 743
             except Exception, e:
739 744
                 if getattr(e, 'silent_variable_failure', False):
740 745
                     current = settings.TEMPLATE_STRING_IF_INVALID
8  tests/regressiontests/templates/tests.py
@@ -100,6 +100,11 @@ class SilentGetItemClass(object):
100 100
     def __getitem__(self, key):
101 101
         raise SomeException
102 102
 
  103
+class SilentAttrClass(object):
  104
+    def b(self):
  105
+        raise SomeException
  106
+    b = property(b)
  107
+
103 108
 class UTF8Class:
104 109
     "Class whose __str__ returns non-ASCII data"
105 110
     def __str__(self):
@@ -350,8 +355,9 @@ def get_template_tests(self):
350 355
 
351 356
             # regression test for ticket #12554
352 357
             # make sure a silent_variable_failure Exception is supressed
353  
-            # on dictionary lookup
  358
+            # on dictionary and attribute lookup
354 359
             'basic-syntax28': ("{{ a.b }}", {'a': SilentGetItemClass()}, ('', 'INVALID')),
  360
+            'basic-syntax29': ("{{ a.b }}", {'a': SilentAttrClass()}, ('', 'INVALID')),
355 361
 
356 362
             # List-index syntax allows a template to access a certain item of a subscriptable object.
357 363
             'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"),

0 notes on commit ef41bd4

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