1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Avoided unnecessary usage of RawSQL.

This ensures proper alias quoting.
This commit is contained in:
Simon Charette 2022-11-15 00:15:25 -05:00 committed by Mariusz Felisiak
parent 7a5307974a
commit 7adb0c8b60

View File

@ -441,11 +441,11 @@ class SQLCompiler:
# Add column used in ORDER BY clause to the selected
# columns and to each combined query.
order_by_idx = len(self.query.select) + 1
col_name = f"__orderbycol{order_by_idx}"
col_alias = f"__orderbycol{order_by_idx}"
for q in self.query.combined_queries:
q.add_annotation(expr_src, col_name)
self.query.add_select_col(resolved, col_name)
resolved.set_source_expressions([RawSQL(f"{order_by_idx}", ())])
q.add_annotation(expr_src, col_alias)
self.query.add_select_col(resolved, col_alias)
resolved.set_source_expressions([Ref(col_alias, src)])
sql, params = self.compile(resolved)
# Don't add the same column twice, but the order direction is
# not taken into account so we strip it. When this entire method