Ticket #12554: r12819_with_tests_dict.diff

File r12819_with_tests_dict.diff, 2.0 KB (added by Colin Copeland, 15 years ago)

Only dict lookup fix and test

  • django/template/__init__.py

     
    745745                            TypeError,  # unsubscriptable object
    746746                            ):
    747747                        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
    753753
    754754        return current
    755755
  • tests/regressiontests/templates/tests.py

     
    9797    def method(self):
    9898        return "OtherClass.method"
    9999
     100class SilentGetItemClass(object):
     101    def __getitem__(self, key):
     102        raise SomeException
     103
    100104class UTF8Class:
    101105    "Class whose __str__ returns non-ASCII data"
    102106    def __str__(self):
     
    465469            'basic-syntax26': (r'{{ "\"fred\"" }}', {}, "\"fred\""),
    466470            'basic-syntax27': (r'{{ _("\"fred\"") }}', {}, "\"fred\""),
    467471
     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
    468477            # List-index syntax allows a template to access a certain item of a subscriptable object.
    469478            'list-index01': ("{{ var.1 }}", {"var": ["first item", "second item"]}, "second item"),
    470479
Back to Top