diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-01-07 00:02:31 -0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-08 10:20:48 +0100 |
| commit | 42e8f264ce55710056b0033682ec6fd662a25b29 (patch) | |
| tree | 19fb128be8a41b2bba9b3a36a09b48bdb75dd346 /django | |
| parent | 7617d5be94a6e348d5ddf4644985b24235822034 (diff) | |
Fixed #36065 -- Fixed ordering by expression referencing composite primary key.
Thanks Jacob Walls for the report and test and Csirmaz Bendegúz for the review.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/expressions.py | 10 | ||||
| -rw-r--r-- | django/db/models/sql/compiler.py | 3 |
2 files changed, 11 insertions, 2 deletions
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 746fe04143..2494ec4139 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1861,6 +1861,16 @@ class OrderBy(Expression): return [self.expression] def as_sql(self, compiler, connection, template=None, **extra_context): + if isinstance(self.expression, ColPairs): + sql_parts = [] + params = [] + for col in self.expression.get_cols(): + copy = self.copy() + copy.set_source_expressions([col]) + sql, col_params = compiler.compile(copy) + sql_parts.append(sql) + params.extend(col_params) + return ", ".join(sql_parts), params template = template or self.template if connection.features.supports_order_by_nulls_modifier: if self.nulls_last: diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 5bb491d823..251cc08e51 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1117,10 +1117,9 @@ class SQLCompiler: ) return results targets, alias, _ = self.query.trim_joins(targets, joins, path) - target_fields = composite.unnest(targets) return [ (OrderBy(transform_function(t, alias), descending=descending), False) - for t in target_fields + for t in targets ] def _setup_joins(self, pieces, opts, alias): |
