From 77278929c86168f075600d9d8c8e76a4792e672b Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Fri, 15 Dec 2023 21:00:59 -0500 Subject: Fixed #35042 -- Fixed a count() crash on combined queries. Regression in 59bea9efd2768102fc9d3aedda469502c218e9b7. Thanks Marcin for the report. --- django/db/models/sql/query.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'django/db/models/sql/query.py') diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 2bc16b1df3..7166b8cb5d 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -520,11 +520,11 @@ class Query(BaseExpression): self.model._meta.pk.get_col(inner_query.get_initial_alias()), ) inner_query.default_cols = False - if not qualify: + if not qualify and not self.combinator: # Mask existing annotations that are not referenced by # aggregates to be pushed to the outer query unless - # filtering against window functions is involved as it - # requires complex realising. + # filtering against window functions or if the query is + # combined as both would require complex realiasing logic. annotation_mask = set() if isinstance(self.group_by, tuple): for expr in self.group_by: -- cgit v1.3