0
0
mirror of https://github.com/django/django.git synced 2024-11-23 18:37:34 +01:00

Refs #35844 -- Fixed copying BaseContext and its subclasses on Python 3.14+.

super objects are copyable on Python 3.14+:

5ca4e34bc1

and can no longer be used in BaseContext.__copy__().
This commit is contained in:
Mariusz Felisiak 2024-11-17 16:07:23 +01:00 committed by Sarah Boyce
parent e035db1bc3
commit 8d7b1423f8
2 changed files with 11 additions and 1 deletions

View File

@ -37,7 +37,9 @@ class BaseContext:
self.dicts.append(value)
def __copy__(self):
duplicate = copy(super())
duplicate = BaseContext()
duplicate.__class__ = self.__class__
duplicate.__dict__ = copy(self.__dict__)
duplicate.dicts = self.dicts[:]
return duplicate

View File

@ -1,3 +1,4 @@
from copy import copy
from unittest import mock
from django.http import HttpRequest
@ -314,3 +315,10 @@ class RequestContextTests(SimpleTestCase):
with self.assertRaisesMessage(TypeError, msg):
with request_context.bind_template(Template("")):
pass
def test_context_copyable(self):
request_context = RequestContext(HttpRequest())
request_context_copy = copy(request_context)
self.assertIsInstance(request_context_copy, RequestContext)
self.assertEqual(request_context_copy.dicts, request_context.dicts)
self.assertIsNot(request_context_copy.dicts, request_context.dicts)