]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Fix custom contexts in fast resolve mode
authorAdrian Moennich <adrian@planetcoding.net>
Wed, 15 Mar 2017 18:19:04 +0000 (19:19 +0100)
committerAdrian Moennich <adrian@planetcoding.net>
Wed, 15 Mar 2017 18:19:04 +0000 (19:19 +0100)
closes #675

CHANGES
jinja2/runtime.py
tests/test_regression.py

diff --git a/CHANGES b/CHANGES
index fb14601e4ba0eab0778c0306cc7bc9c85940df24..a3cba109ac8f7c0d0ea3735cdb81a2afd719db8e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,12 @@
 Jinja2 Changelog
 ================
 
+Version 2.9.6
+-------------
+(bugfix release, release date to be decided)
+
+- Fixed custom context behavior in fast resolve mode (#675)
+
 Version 2.9.5
 -------------
 (bugfix release, released on January 28th 2017)
index 24430016962c1cb541a42d35cf5289bf93d8c3e6..00d5f03ca610252a176872f7b1b0cbd431f0609e 100644 (file)
@@ -11,6 +11,8 @@
 import sys
 
 from itertools import chain
+from types import MethodType
+
 from jinja2.nodes import EvalContext, _context_function_types
 from jinja2.utils import Markup, soft_unicode, escape, missing, concat, \
      internalcode, object_type_repr, evalcontextfunction
@@ -167,7 +169,7 @@ class Context(with_metaclass(ContextMeta)):
         # In case we detect the fast resolve mode we can set up an alias
         # here that bypasses the legacy code logic.
         if self._fast_resolve_mode:
-            self.resolve_or_missing = resolve_or_missing
+            self.resolve_or_missing = MethodType(resolve_or_missing, self)
 
     def super(self, name, current):
         """Render a parent block."""
index f2314dee0459fba15bd55593c32a17a547dbdbb4..8bd26788eaf6a19b07d2dd1a4fdb6145a31f5d34 100644 (file)
@@ -506,6 +506,20 @@ class TestBug(object):
         assert repr(t) == "('foo', [1, 2])"
         assert str(t) == "('foo', [1, 2])"
 
+    def test_custom_context(self, env):
+        from jinja2.runtime import Context
+
+        class MyContext(Context):
+            pass
+
+        class MyEnvironment(Environment):
+            context_class = MyContext
+
+        loader = DictLoader({'base': '{{ foobar }}',
+                             'test': '{% extends "base" %}'})
+        env = MyEnvironment(loader=loader)
+        assert env.get_template('test').render(foobar='test') == 'test'
+
     def test_legacy_custom_context(self, env):
         from jinja2.runtime import Context, Undefined, missing