summaryrefslogtreecommitdiff
path: root/tests/queries
diff options
context:
space:
mode:
authorHisham Mahmood <hishammahmood41@gmail.com>2024-02-06 19:40:01 +0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-02-07 12:36:30 +0100
commitd79fba7d8e7bbcdf53535a14d57ead5a6863cd8d (patch)
tree1f888d03d2cf1c644acd48f8f2dd573c4341076e /tests/queries
parent6ee37ada3241ed263d8d1c2901b030d964cbd161 (diff)
Fixed #35099 -- Prevented mutating queryset when combining with & and | operators.
Thanks Alan for the report. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/queries')
-rw-r--r--tests/queries/tests.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 48d610bb2b..7ac8a65d42 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -1357,6 +1357,24 @@ class Queries1Tests(TestCase):
)
self.assertSequenceEqual(Note.objects.exclude(negate=True), [self.n3])
+ def test_combining_does_not_mutate(self):
+ all_authors = Author.objects.all()
+ authors_with_report = Author.objects.filter(
+ Exists(Report.objects.filter(creator__pk=OuterRef("id")))
+ )
+ authors_without_report = all_authors.exclude(pk__in=authors_with_report)
+ items_before = Item.objects.filter(creator__in=authors_without_report)
+ self.assertCountEqual(items_before, [self.i2, self.i3, self.i4])
+ # Combining querysets doesn't mutate them.
+ all_authors | authors_with_report
+ all_authors & authors_with_report
+
+ authors_without_report = all_authors.exclude(pk__in=authors_with_report)
+ items_after = Item.objects.filter(creator__in=authors_without_report)
+
+ self.assertCountEqual(items_after, [self.i2, self.i3, self.i4])
+ self.assertCountEqual(items_before, items_after)
+
class Queries2Tests(TestCase):
@classmethod