summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-07-17 12:51:54 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-19 08:21:33 +0200
commit68912e4f6f84f21322f92a2c7b6c77f68f91b9c9 (patch)
tree1e6ea2bc0eccadcdbd86bb6aae316bf24066ad48 /django/db/models/sql/query.py
parentf8c43aca467b7b0c4bb0a7fa41362f90b610b8df (diff)
Fixed #34717 -- Fixed QuerySet.aggregate() crash when referencing window functions.
Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7. Refs #28477. Thanks younes-chaoui for the report.
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 13a6809dd8..1608d19480 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -403,6 +403,7 @@ class Query(BaseExpression):
# Store annotation mask prior to temporarily adding aggregations for
# resolving purpose to facilitate their subsequent removal.
refs_subquery = False
+ refs_window = False
replacements = {}
annotation_select_mask = self.annotation_select_mask
for alias, aggregate_expr in aggregate_exprs.items():
@@ -419,6 +420,10 @@ class Query(BaseExpression):
getattr(self.annotations[ref], "subquery", False)
for ref in aggregate.get_refs()
)
+ refs_window |= any(
+ getattr(self.annotations[ref], "contains_over_clause", True)
+ for ref in aggregate.get_refs()
+ )
aggregate = aggregate.replace_expressions(replacements)
self.annotations[alias] = aggregate
replacements[Ref(alias, aggregate)] = aggregate
@@ -451,6 +456,7 @@ class Query(BaseExpression):
or self.is_sliced
or has_existing_aggregation
or refs_subquery
+ or refs_window
or qualify
or self.distinct
or self.combinator