From a46bc327e70f81b66800780edf3830f6137a89e3 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 4 Mar 2022 09:51:52 +0100 Subject: [PATCH] Refs #11293 -- Added test for filtering aggregates with negated & operator. --- tests/aggregation_regress/tests.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py index 9582d90a96..fb9d4ca92b 100644 --- a/tests/aggregation_regress/tests.py +++ b/tests/aggregation_regress/tests.py @@ -1682,7 +1682,7 @@ class AggregationTests(TestCase): qs, ["Adrian Holovaty", "Peter Norvig"], lambda b: b.name ) - def test_ticket_11293(self): + def test_filter_aggregates_or_connector(self): q1 = Q(price__gt=50) q2 = Q(authors__count__gt=1) query = Book.objects.annotate(Count("authors")).filter(q1 | q2).order_by("pk") @@ -1692,6 +1692,18 @@ class AggregationTests(TestCase): attrgetter("pk"), ) + def test_filter_aggregates_negated_and_connector(self): + q1 = Q(price__gt=50) + q2 = Q(authors__count__gt=1) + query = ( + Book.objects.annotate(Count("authors")).filter(~(q1 & q2)).order_by("pk") + ) + self.assertQuerysetEqual( + query, + [self.b1.pk, self.b2.pk, self.b3.pk, self.b4.pk, self.b6.pk], + attrgetter("pk"), + ) + def test_ticket_11293_q_immutable(self): """ Splitting a q object to parts for where/having doesn't alter