mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #24923 -- errored out nicely when using aggregates in order_by()
This commit is contained in:
committed by
Tim Graham
parent
83f6373030
commit
6f403056f0
@@ -1643,6 +1643,11 @@ class Query(object):
|
||||
for item in ordering:
|
||||
if not hasattr(item, 'resolve_expression') and not ORDER_PATTERN.match(item):
|
||||
errors.append(item)
|
||||
if getattr(item, 'contains_aggregate', False):
|
||||
raise FieldError(
|
||||
'Using an aggregate in order_by() without also including '
|
||||
'it in annotate() is not allowed: %s' % item
|
||||
)
|
||||
if errors:
|
||||
raise FieldError('Invalid order_by arguments: %s' % errors)
|
||||
if ordering:
|
||||
|
||||
Reference in New Issue
Block a user