mirror of
https://github.com/django/django.git
synced 2025-10-02 23:04:53 +00:00
[4.0.x] Fixed #33159 -- Reverted "Fixed #32970 -- Changed WhereNode.clone() to create a shallow copy of children."
This reverts commite441847eca
. A shallow copy is not enough because querysets can be reused and evaluated in nested nodes, which shouldn't mutate JOIN aliases. Thanks Michal Čihař for the report. Backport of903aaa35e5
from main
This commit is contained in:
parent
b2a0978610
commit
93a42d43a6
2 changed files with 11 additions and 1 deletions
|
@ -148,7 +148,11 @@ class WhereNode(tree.Node):
|
|||
clone = self.__class__._new_instance(
|
||||
children=None, connector=self.connector, negated=self.negated,
|
||||
)
|
||||
clone.children = self.children[:]
|
||||
for child in self.children:
|
||||
if hasattr(child, 'clone'):
|
||||
clone.children.append(child.clone())
|
||||
else:
|
||||
clone.children.append(child)
|
||||
return clone
|
||||
|
||||
def relabeled_clone(self, change_map):
|
||||
|
|
|
@ -1663,6 +1663,12 @@ class Queries5Tests(TestCase):
|
|||
'bar %s'
|
||||
)
|
||||
|
||||
def test_queryset_reuse(self):
|
||||
# Using querysets doesn't mutate aliases.
|
||||
authors = Author.objects.filter(Q(name='a1') | Q(name='nonexistent'))
|
||||
self.assertEqual(Ranking.objects.filter(author__in=authors).get(), self.rank3)
|
||||
self.assertEqual(authors.count(), 1)
|
||||
|
||||
|
||||
class SelectRelatedTests(TestCase):
|
||||
def test_tickets_3045_3288(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue