diff --git a/django/template/base.py b/django/template/base.py index d97ee81326..778d82be55 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -892,9 +892,8 @@ class Variable(object): raise AttributeError current = getattr(current, bit) except (TypeError, AttributeError) as e: - # Reraise an AttributeError raised by a @property - if (isinstance(e, AttributeError) and - not isinstance(current, BaseContext) and bit in dir(current)): + # Reraise if the exception was raised by a @property + if not isinstance(current, BaseContext) and bit in dir(current): raise try: # list-index lookup current = current[int(bit)] diff --git a/tests/template_tests/syntax_tests/test_filter_syntax.py b/tests/template_tests/syntax_tests/test_filter_syntax.py index e9f0491d6e..3e524a61eb 100644 --- a/tests/template_tests/syntax_tests/test_filter_syntax.py +++ b/tests/template_tests/syntax_tests/test_filter_syntax.py @@ -237,3 +237,8 @@ class FilterSyntaxTests(SimpleTestCase): """ with self.assertRaises(AttributeError): self.engine.render_to_string('filter-syntax25', {'var': SomeClass()}) + + @setup({'template': '{{ var.type_error_attribute }}'}) + def test_type_error_attribute(self): + with self.assertRaises(TypeError): + self.engine.render_to_string('template', {'var': SomeClass()}) diff --git a/tests/template_tests/utils.py b/tests/template_tests/utils.py index f8585979d7..1747f080bc 100644 --- a/tests/template_tests/utils.py +++ b/tests/template_tests/utils.py @@ -137,6 +137,10 @@ class SomeClass: def attribute_error_attribute(self): raise AttributeError + @property + def type_error_attribute(self): + raise TypeError + class OtherClass: def method(self):