diff options
| author | Ed Rivas <ed@jerivas.com> | 2022-05-04 18:10:53 -0600 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-05-12 07:19:16 +0200 |
| commit | 2798c937deb6625a4e6a36e70d4d60ce5faac954 (patch) | |
| tree | 0a07339d337eb923642cfd9ea6930c8a6f4e4bab /django/db/models/sql | |
| parent | 34e2148fc725e7200050f74130d7523e3cd8507a (diff) | |
Fixed #29538 -- Fixed crash of ordering by related fields when Meta.ordering contains expressions.
Thanks Simon Charette for the review.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/compiler.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 13b606255c..9c7bd8ea1a 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -912,10 +912,15 @@ class SQLCompiler: ): item = item.desc() if descending else item.asc() if isinstance(item, OrderBy): - results.append((item, False)) + results.append( + (item.prefix_references(f"{name}{LOOKUP_SEP}"), False) + ) continue results.extend( - self.find_ordering_name(item, opts, alias, order, already_seen) + (expr.prefix_references(f"{name}{LOOKUP_SEP}"), is_ref) + for expr, is_ref in self.find_ordering_name( + item, opts, alias, order, already_seen + ) ) return results targets, alias, _ = self.query.trim_joins(targets, joins, path) |
