Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12554: Silence exceptions that have specified silent_variable_…

…failure=True. Thanks Thomas Steinacher, copelco, mlavin.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12823 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2403f581b3cd0e7528f4b60c712f460fed91e2c2 1 parent 10884ec
Karen Tracey authored March 20, 2010
10  django/template/__init__.py
@@ -745,11 +745,11 @@ def _resolve_lookup(self, context):
745 745
                             TypeError,  # unsubscriptable object
746 746
                             ):
747 747
                         raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute
748  
-                except Exception, e:
749  
-                    if getattr(e, 'silent_variable_failure', False):
750  
-                        current = settings.TEMPLATE_STRING_IF_INVALID
751  
-                    else:
752  
-                        raise
  748
+            except Exception, e:
  749
+                if getattr(e, 'silent_variable_failure', False):
  750
+                    current = settings.TEMPLATE_STRING_IF_INVALID
  751
+                else:
  752
+                    raise
753 753
 
754 754
         return current
755 755
 
9  tests/regressiontests/templates/tests.py
@@ -97,6 +97,10 @@ class OtherClass:
97 97
     def method(self):
98 98
         return "OtherClass.method"
99 99
 
  100
+class SilentGetItemClass(object):
  101
+    def __getitem__(self, key):
  102
+        raise SomeException
  103
+
100 104
 class UTF8Class:
101 105
     "Class whose __str__ returns non-ASCII data"
102 106
     def __str__(self):
@@ -465,6 +469,11 @@ def get_template_tests(self):
465 469
             'basic-syntax26': (r'{{ "\"fred\"" }}', {}, "\"fred\""),
466 470
             'basic-syntax27': (r'{{ _("\"fred\"") }}', {}, "\"fred\""),
467 471
 
  472
+            # regression test for ticket #12554
  473
+            # make sure a silent_variable_failure Exception is supressed
  474
+            # on dictionary lookup
  475
+            'basic-syntax28': ("{{ a.b }}", {'a': SilentGetItemClass()}, ('', 'INVALID')),
  476
+
468 477
             # List-index syntax allows a template to access a certain item of a subscriptable object.
469 478
             'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"),
470 479
 

0 notes on commit 2403f58

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