diff --git a/CHANGES b/CHANGES index fac3b8d3b..8a160d79a 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,9 @@ Version 2.9.3 intended behavior in all situations however it does not restore the old behavior where limited assignments to outer scopes was possible. For more information and a discussion see #641 +- Resolved an issue where `block scoped` would not take advantage of the + new scoping rules. In some more exotic cases a variable overriden in a + local scope would not make it into a block. Version 2.9.2 ------------- diff --git a/jinja2/runtime.py b/jinja2/runtime.py index 958ddfd42..5c2089b8c 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -214,10 +214,12 @@ def call(__self, __obj, *args, **kwargs): 'StopIteration exception') def derived(self, locals=None): - """Internal helper function to create a derived context.""" + """Internal helper function to create a derived context. This is + used in situations where the system needs a new context in the same + template that is independent. + """ context = new_context(self.environment, self.name, {}, - self.parent, True, None, locals) - context.vars.update(self.vars) + self.get_all(), True, None, locals) context.eval_ctx = self.eval_ctx context.blocks.update((k, list(v)) for k, v in iteritems(self.blocks)) return context diff --git a/tests/test_regression.py b/tests/test_regression.py index fe16edeef..1706c8b51 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -447,3 +447,8 @@ def test_macro_blocks(self, env): t = env.from_string('{% macro x() %}{% block foo %}x{% ' 'endblock %}{% endmacro %}{{ x() }}') assert t.render() == 'x' + + def test_scoped_block(self, env): + t = env.from_string('{% set x = 1 %}{% with x = 2 %}{% block y scoped %}' + '{{ x }}{% endblock %}{% endwith %}') + assert t.render() == '2'