From d63ac5b595694c44ed8a64d782a177d2f92125d9 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Tue, 16 Sep 2014 12:17:33 +0200 Subject: [PATCH] Fixed #23492 -- Restored F.__deepcopy__. This reverts commit 3a66035107a640c4905f0a5f247a45f32dbe16d7. A regression test was also added. --- django/db/models/expressions.py | 5 +++++ tests/expressions/tests.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index c23767d486..5484ca7f47 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -145,6 +145,11 @@ class F(ExpressionNode): super(F, self).__init__(None, None, False) self.name = name + def __deepcopy__(self, memodict): + obj = super(F, self).__deepcopy__(memodict) + obj.name = self.name + return obj + def prepare(self, evaluator, query, allow_joins): return evaluator.prepare_leaf(self, query, allow_joins) diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 2bc40956a7..36cb95a5f7 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +from copy import deepcopy import datetime from django.core.exceptions import FieldError @@ -287,6 +288,14 @@ class ExpressionsTests(TestCase): ) self.assertEqual(str(qs.query).count('JOIN'), 2) + def test_F_object_deepcopy(self): + """ + Make sure F objects can be deepcopied (#23492) + """ + f = F("foo") + g = deepcopy(f) + self.assertEqual(f.name, g.name) + class ExpressionsNumericTests(TestCase):