mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[2.2.x] Fixed #30332 -- Fixed crash of ordering by expressions with params in ArrayAgg and StringAgg.
Backport of d0315584b5 from master.
This commit is contained in:
committed by
Mariusz Felisiak
parent
9da25fb832
commit
268ed9cd8a
@@ -21,13 +21,17 @@ class OrderableAggMixin:
|
||||
|
||||
def as_sql(self, compiler, connection):
|
||||
if self.ordering:
|
||||
self.extra['ordering'] = 'ORDER BY ' + ', '.join((
|
||||
ordering_element.as_sql(compiler, connection)[0]
|
||||
for ordering_element in self.ordering
|
||||
ordering_params = []
|
||||
ordering_expr_sql = []
|
||||
for expr in self.ordering:
|
||||
expr_sql, expr_params = expr.as_sql(compiler, connection)
|
||||
ordering_expr_sql.append(expr_sql)
|
||||
ordering_params.extend(expr_params)
|
||||
sql, sql_params = super().as_sql(compiler, connection, ordering=(
|
||||
'ORDER BY ' + ', '.join(ordering_expr_sql)
|
||||
))
|
||||
else:
|
||||
self.extra['ordering'] = ''
|
||||
return super().as_sql(compiler, connection)
|
||||
return sql, sql_params + ordering_params
|
||||
return super().as_sql(compiler, connection, ordering='')
|
||||
|
||||
def get_source_expressions(self):
|
||||
return self.source_expressions + self.ordering
|
||||
|
||||
Reference in New Issue
Block a user