From: Armin Ronacher Date: Mon, 2 Jan 2017 20:35:57 +0000 (+0100) Subject: Fixed from imports with context X-Git-Tag: 2.9~30^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76edefaf359a9608351c5be0f634ba8a2d27fa7f;p=thirdparty%2Fjinja.git Fixed from imports with context --- diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 9a6438c5..04569f3a 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -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: diff --git a/tests/test_imports.py b/tests/test_imports.py index 643c995c..ade253ed 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -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'