From 5fbec369aa32d1717b7bffc169649ab5896a7ad9 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Thu, 5 Feb 2015 13:20:33 +0100 Subject: [PATCH] [1.8.x] Fixed #24273 -- Allowed copying RequestContext more than once. Thanks Collin Anderson for the report. Backport of 31d3a355 from master --- django/template/context.py | 3 ++- tests/template_tests/test_context.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/django/template/context.py b/django/template/context.py index d72c70c37a1..9543931cec0 100644 --- a/django/template/context.py +++ b/django/template/context.py @@ -232,5 +232,6 @@ class RequestContext(Context): new_context = super(RequestContext, self).new(values) # This is for backwards-compatibility: RequestContexts created via # Context.new don't include values from context processors. - del new_context._processors_index + if hasattr(new_context, '_processors_index'): + del new_context._processors_index return new_context diff --git a/tests/template_tests/test_context.py b/tests/template_tests/test_context.py index c5ad3e1d507..24d589fb25a 100644 --- a/tests/template_tests/test_context.py +++ b/tests/template_tests/test_context.py @@ -2,7 +2,8 @@ from unittest import TestCase -from django.template import Context, Variable, VariableDoesNotExist +from django.http import HttpRequest +from django.template import Context, RequestContext, Variable, VariableDoesNotExist from django.template.context import RenderContext @@ -83,3 +84,7 @@ class ContextTests(TestCase): # make contexts equals again b.update({'a': 1}) self.assertEqual(a, b) + + def test_copy_request_context_twice(self): + # Regression test for #24273 - this doesn't raise an exception + RequestContext(HttpRequest()).new().new()