Refs #11293 -- Added test for filtering aggregates with negated & operator.

This commit is contained in:
Mariusz Felisiak 2022-03-04 09:51:52 +01:00 committed by GitHub
parent b811364421
commit a46bc327e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -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