mirror of
https://github.com/django/django.git
synced 2025-11-29 06:51:10 +00:00
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.
This commit is contained in:
parent
4237050684
commit
98ea4f0f46
4 changed files with 44 additions and 4 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue