Fixed #34024 -- Fixed crash when aggregating querysets with Q objects annotations.

This reverts b64db05b9c.

It was reasonable to assume it was unnecessary code as there were
no failing tests upon its removal. This commit adds the necessary
regression tests for the failing condition identified in #34024
alongside the original tests added in the PR for which
WhereNode.is_summary was introduced.
This commit is contained in:
David Sanders 2022-09-24 00:15:03 +10:00 committed by GitHub
parent 37a13cc92d
commit 1674c70525
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -244,6 +244,10 @@ class WhereNode(tree.Node):
def contains_over_clause(self):
return self._contains_over_clause(self)
@property
def is_summary(self):
return any(child.is_summary for child in self.children)
@staticmethod
def _resolve_leaf(expr, query, *args, **kwargs):
if hasattr(expr, "resolve_expression"):

View File

@ -554,6 +554,9 @@ class AggregationTests(TestCase):
325,
)
def test_q_annotation_aggregate(self):
self.assertEqual(Book.objects.annotate(has_pk=Q(pk__isnull=False)).count(), 6)
def test_decimal_aggregate_annotation_filter(self):
"""
Filtering on an aggregate annotation with Decimal values should work.