Fixed #23492 -- Restored F.__deepcopy__.

This reverts commit 3a66035107.
A regression test was also added.
This commit is contained in:
Baptiste Mispelon 2014-09-16 12:17:33 +02:00
parent ed7821231b
commit d63ac5b595
2 changed files with 14 additions and 0 deletions

View File

@ -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)

View File

@ -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):