summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2023-03-30 01:23:12 -0400
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-07-03 16:36:25 +0200
commit6d220963fa275a8431fcbcc05de1468f9f8bc3d3 (patch)
tree1cb52cca46cd0e7deaf2ebe918b0324f8cbd0a6e /django/db/models/sql
parent65ad4ade74dc9208b9d686a451cd6045df0c9c3a (diff)
Fixed #28900 -- Propagated all selected fields to combinator queries.
Previously, only the selected column aliases would be propagated and annotations were ignored.
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/compiler.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index d606505cdf..f3aed06d81 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -591,20 +591,15 @@ class SQLCompiler:
# generate valid SQL.
compiler.elide_empty = False
parts = ()
+ selected = self.query.selected
for compiler in compilers:
try:
# If the columns list is limited, then all combined queries
# must have the same columns list. Set the selects defined on
# the query on all combined queries, if not already set.
- if not compiler.query.values_select and self.query.values_select:
+ if selected is not None and compiler.query.selected is None:
compiler.query = compiler.query.clone()
- compiler.query.set_values(
- (
- *self.query.extra_select,
- *self.query.values_select,
- *self.query.annotation_select,
- )
- )
+ compiler.query.set_values(selected)
part_sql, part_args = compiler.as_sql(with_col_aliases=True)
if compiler.query.combinator:
# Wrap in a subquery if wrapping in parentheses isn't