Skip to content
Myr

AttributeError in undefined message doesn't cause RuntimeError

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent e1b5e50 · Browse files · 3 files+25 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+25 added−3 removed

  • tests:+15 added−0 removed
  • other:+10 added−3 removed

3 files+25 added−3 removed

modified:src/jinja2/utils.py+7 added-3 removed
163 unmodified lines
164 if obj is None:165 return "None"166 elif obj is Ellipsis:167 return "Ellipsis"168169 cls = type(obj)170171 # __builtin__ in 2.x, builtins in 3.x169 if obj.__class__.__module__ in ("__builtin__", "builtins"):170 name = obj.__class__.__name__172 if cls.__module__ in ("__builtin__", "builtins"):173 name = cls.__name__174 else:172 name = obj.__class__.__module__ + "." + obj.__class__.__name__175 name = cls.__module__ + "." + cls.__name__176177 return "%s object" % name178179180def pformat(obj, verbose=False):
551 unmodified lines
modified:tests/test_api.py+15 added
267 unmodified lines
268 def test_undefined_and_special_attributes(self):269 with pytest.raises(AttributeError):270 Undefined("Foo").__dict__271272 def test_undefined_attribute_error(self):273 # Django's LazyObject turns the __class__ attribute into a274 # property that resolves the wrapped function. If that wrapped275 # function raises an AttributeError, printing the repr of the276 # object in the undefined message would cause a RecursionError.277 class Error(object):278 @property279 def __class__(self):280 raise AttributeError()281282 u = Undefined(obj=Error(), name="hello")283284 with pytest.raises(UndefinedError):285 getattr(u, "recursion", None)286287 def test_logging_undefined(self):288 _messages = []289290 class DebugLogger(object):
147 unmodified lines
modified:CHANGES.rst+3 added
10 unmodified lines
11- Update ``wordcount`` filter to trigger :class:`Undefined` methods12 by wrapping the input in :func:`soft_unicode`. :pr:`1160`13- Fix a hang when displaying tracebacks on Python 32-bit.14 :issue:`1162`15- Showing an undefined error for an object that raises16 ``AttributeError`` on access doesn't cause a recursion error.17 :issue:`1177`181920Version 2.11.121--------------
737 unmodified lines