summaryrefslogtreecommitdiff
path: root/django/db/models/sql/compiler.py
diff options
context:
space:
mode:
authorDavid Sanders <shang.xiao.sanders@gmail.com>2022-09-18 01:44:37 +1000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-10-04 08:19:34 +0200
commit4771a1694b3b54c7309602820881d3ec9cc2c809 (patch)
tree68b16c5811caf7d67e1f3425bbedb6e81181ead1 /django/db/models/sql/compiler.py
parent649b28eab6765cd6b2b40c779a18ecafc99b43d7 (diff)
Fixed #34012 -- Made QuerySet.order_by() apply transforms on related fields for models with Meta.ordering.
This makes QuerySet.order_by() no longer ignore trailing transforms for models with Meta.ordering. As a consequence, FieldError is raised in such cases for non-existent fields. Thanks to Klaas van Schelven for the report and Mariusz Felisiak for the review and advice.
Diffstat (limited to 'django/db/models/sql/compiler.py')
-rw-r--r--django/db/models/sql/compiler.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index c7efa469a8..4f2783a635 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -1001,12 +1001,14 @@ class SQLCompiler:
# If we get to this point and the field is a relation to another model,
# append the default ordering for that model unless it is the pk
- # shortcut or the attribute name of the field that is specified.
+ # shortcut or the attribute name of the field that is specified or
+ # there are transforms to process.
if (
field.is_relation
and opts.ordering
and getattr(field, "attname", None) != pieces[-1]
and name != "pk"
+ and not getattr(transform_function, "has_transforms", False)
):
# Firstly, avoid infinite loops.
already_seen = already_seen or set()