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