summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-02-27 01:10:19 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-27 07:10:45 +0100
commit872dade29c8a4b9e82920a85c698fcef8ed332ee (patch)
treebad75170eb159805c661e32d1a504be6c4748b82 /django/db/models/sql
parent5a82acbda8c9a7b83030101024def2404318dca9 (diff)
[4.2.x] Fixed #34372 -- Fixed queryset crash on order by aggregation using OrderBy.
Regression in 278881e37619278789942513916acafaa88d26f3 caused by a lack of expression copying when an OrderBy expression is explicitly provided. Thanks Jannis Vajen for the report and regression test. Backport of b15f162f252610e3b510ade465549769ab4356cf from main
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/compiler.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 348cfa381a..1faed5c416 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -358,11 +358,13 @@ class SQLCompiler:
if (
field.nulls_first is None and field.nulls_last is None
) or self.connection.features.supports_order_by_nulls_modifier:
+ field = field.copy()
field.expression = select_ref
# Alias collisions are not possible when dealing with
# combined queries so fallback to it if emulation of NULLS
# handling is required.
elif self.query.combinator:
+ field = field.copy()
field.expression = Ref(select_ref.refs, select_ref.source)
yield field, select_ref is not None
continue