]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Fixed from imports with context
authorArmin Ronacher <armin.ronacher@active-4.com>
Mon, 2 Jan 2017 20:35:57 +0000 (21:35 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Tue, 3 Jan 2017 22:45:29 +0000 (23:45 +0100)
jinja2/compiler.py
tests/test_imports.py

index 9a6438c55fd93d215c4938e895e830e24556850d..04569f3a866e5f7c08f1468c21cf9a3284da2fef 100644 (file)
@@ -791,8 +791,9 @@ class CodeGenerator(NodeVisitor):
         self.visit(node.template, frame)
         self.write(', %r).' % self.name)
         if node.with_context:
-            self.write('make_module%s(context.parent, True)'
-                       % (self.environment.is_async and '_async' or ''))
+            self.write('make_module%s(context.parent, True, %s)'
+                       % (self.environment.is_async and '_async' or '',
+                          self.dump_local_context(frame)))
         elif self.environment.is_async:
             self.write('_get_default_module_async()')
         else:
index 643c995c6e6ade0cbdc6414f5ffa7907ca607635..ade253edc3a2fb5db2de87d49690178902026554 100644 (file)
@@ -146,3 +146,11 @@ class TestIncludes():
             {{ outer("FOO") }}
         """)
         assert t.render().strip() == '(FOO)'
+
+    def test_import_from_with_context(self):
+        env = Environment(loader=DictLoader({
+            'a': '{% macro x() %}{{ foobar }}{% endmacro %}',
+        }))
+        t = env.from_string('{% set foobar = 42 %}{% from "a" '
+                            'import x with context %}{{ x() }}')
+        assert t.render() == '42'