diff --git a/django/template/context.py b/django/template/context.py index 3830c1c660..79d0b6f505 100644 --- a/django/template/context.py +++ b/django/template/context.py @@ -180,5 +180,7 @@ class RequestContext(Context): processors = () else: processors = tuple(processors) + updates = dict() for processor in get_standard_processors() + processors: - self.update(processor(request)) + updates.update(processor(request)) + self.update(updates) diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index c2179b43c1..e9c0a0f7c4 100644 --- a/tests/template_tests/tests.py +++ b/tests/template_tests/tests.py @@ -1843,3 +1843,12 @@ class RequestContextTests(unittest.TestCase): template.Template('{% include "child" only %}').render(ctx), 'none' ) + + def test_stack_size(self): + """ + Regression test for #7116, Optimize RequetsContext construction + """ + ctx = RequestContext(self.fake_request, {}) + # The stack should now contain 3 items: + # [builtins, supplied context, context processor] + self.assertEqual(len(ctx.dicts), 3)