[1.7.x] Fixed #23492 -- Restored F.__deepcopy__.
This reverts commit3a66035107
. A regression test was also added. Backport ofd63ac5b595
from master.
This commit is contained in:
parent
68ab3b1ac1
commit
04e7c7d51f
|
@ -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)
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from django.core.exceptions import FieldError
|
||||
from django.db.models import F
|
||||
from django.db import transaction
|
||||
|
@ -281,3 +283,11 @@ class ExpressionsTests(TestCase):
|
|||
company_ceo_set__num_employees=F('company_ceo_set__num_employees')
|
||||
)
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue