diff options
| author | Simon Charette <charette.s@gmail.com> | 2020-04-05 15:32:54 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-04-06 10:01:02 +0200 |
| commit | 98ea4f0f4696221f00e111f1d623452002192e6c (patch) | |
| tree | 74685334d5a200d34e270701252f53e29d903a4e /django/db/models/sql | |
| parent | 4237050684427db45ea834fe89d9e11c0520201e (diff) | |
Refs #7098 -- Deprecated passing raw column aliases to order_by().
Now that order_by() has expression support passing RawSQL() can achieve
the same result.
This was also already supported through QuerySet.extra(order_by) for
years but this API is more or less deprecated at this point.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index e5524a8198..82ff6bf4ea 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1895,7 +1895,16 @@ class Query(BaseExpression): """ errors = [] for item in ordering: - if not hasattr(item, 'resolve_expression') and not ORDER_PATTERN.match(item): + if isinstance(item, str) and ORDER_PATTERN.match(item): + if '.' in item: + warnings.warn( + 'Passing column raw column aliases to order_by() is ' + 'deprecated. Wrap %r in a RawSQL expression before ' + 'passing it to order_by().' % item, + category=RemovedInDjango40Warning, + stacklevel=3, + ) + elif not hasattr(item, 'resolve_expression'): errors.append(item) if getattr(item, 'contains_aggregate', False): raise FieldError( |
