]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
add changelog and test 1146/head
authorDavid Lord <davidism@gmail.com>
Tue, 4 Feb 2020 16:46:53 +0000 (08:46 -0800)
committerDavid Lord <davidism@gmail.com>
Tue, 4 Feb 2020 16:57:39 +0000 (08:57 -0800)
CHANGES.rst
tests/test_runtime.py

index 9ec8a3a4ad8c89482581cdb2bc391fd5a45fd63f..651ab43089dbc0d32ebfb4d349a88644236e56b2 100644 (file)
@@ -1,9 +1,20 @@
 .. currentmodule:: jinja2
 
+2.11.2
+------
+
+Unreleased
+
+-   Fix a bug that caused callable objects with ``__getattr__``, like
+    :class:`~unittest.mock.Mock` to be treated as a
+    :func:`contextfunction`. :issue:`1145`
+
+
+
 Version 2.11.1
 --------------
 
-Unreleased
+Released 2020-01-30
 
 -   Fix a bug that prevented looking up a key after an attribute
     (``{{ data.items[1:] }}``) in an async template. :issue:`1141`
index d24f2660cf0c1c1d53115765ef939372a776f513..5e4686c083141d3ffa48d28136daa151ce7f8e52 100644 (file)
@@ -54,3 +54,22 @@ def test_iterator_not_advanced_early():
     # groupby groups depend on the current position of the iterator. If
     # it was advanced early, the lists would appear empty.
     assert out == "1 [(1, 'a'), (1, 'b')]\n2 [(2, 'c')]\n3 [(3, 'd')]\n"
+
+
+def test_mock_not_contextfunction():
+    """If a callable class has a ``__getattr__`` that returns True-like
+    values for arbitrary attrs, it should not be incorrectly identified
+    as a ``contextfunction``.
+    """
+
+    class Calc(object):
+        def __getattr__(self, item):
+            return object()
+
+        def __call__(self, *args, **kwargs):
+            return len(args) + len(kwargs)
+
+    t = Template("{{ calc() }}")
+    out = t.render(calc=Calc())
+    # Would be "1" if context argument was passed.
+    assert out == "0"