Skip to content

Commit

Permalink
Reduced nesting inside Query.get_aggregation().
Browse files Browse the repository at this point in the history
  • Loading branch information
charettes authored and felixxm committed Nov 14, 2022
1 parent 1003713 commit 1771998
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions django/db/models/sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,13 @@ def get_aggregation(self, using, added_aggregate_names):
# and move them to the outer AggregateQuery.
col_cnt = 0
for alias, expression in list(inner_query.annotation_select.items()):
if not expression.is_summary:
continue
annotation_select_mask = inner_query.annotation_select_mask
if expression.is_summary:
expression, col_cnt = inner_query.rewrite_cols(expression, col_cnt)
outer_query.annotations[alias] = expression.relabeled_clone(
relabels
)
del inner_query.annotations[alias]
annotation_select_mask.remove(alias)
expression, col_cnt = inner_query.rewrite_cols(expression, col_cnt)
outer_query.annotations[alias] = expression.relabeled_clone(relabels)
del inner_query.annotations[alias]
annotation_select_mask.remove(alias)
# Make sure the annotation_select wont use cached results.
inner_query.set_annotation_mask(inner_query.annotation_select_mask)
if (
Expand Down

0 comments on commit 1771998

Please sign in to comment.