From 903aaa35e5ceaa33bfc9b19b7f6da65ce5a91dd4 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 30 Sep 2021 11:26:17 +0200 Subject: Fixed #33159 -- Reverted "Fixed #32970 -- Changed WhereNode.clone() to create a shallow copy of children." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e441847ecae99dd1ccd0d9ce76dbcff51afa863c. 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. --- tests/queries/tests.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/queries/tests.py b/tests/queries/tests.py index fa87e7859c..9c1b41a395 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -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): -- cgit v1.3