Fixed #33262 -- Fixed crash of conditional aggregation on Exists().
This commit is contained in:
parent
25157033e9
commit
a934d377af
|
@ -30,7 +30,7 @@ class OrderableAggMixin:
|
|||
sql, sql_params = super().as_sql(compiler, connection, ordering=(
|
||||
'ORDER BY ' + ', '.join(ordering_expr_sql)
|
||||
))
|
||||
return sql, sql_params + ordering_params
|
||||
return sql, (*sql_params, *ordering_params)
|
||||
return super().as_sql(compiler, connection, ordering='')
|
||||
|
||||
def set_source_expressions(self, exprs):
|
||||
|
|
|
@ -87,7 +87,7 @@ class Aggregate(Func):
|
|||
compiler, connection, template=template, filter=filter_sql,
|
||||
**extra_context
|
||||
)
|
||||
return sql, params + filter_params
|
||||
return sql, (*params, *filter_params)
|
||||
else:
|
||||
copy = self.copy()
|
||||
copy.filter = None
|
||||
|
|
|
@ -141,3 +141,11 @@ class FilteredAggregateTests(TestCase):
|
|||
)
|
||||
)
|
||||
self.assertEqual(aggregate, {'max_rating': 4.5})
|
||||
|
||||
def test_filtered_aggregate_on_exists(self):
|
||||
aggregate = Book.objects.values('publisher').aggregate(
|
||||
max_rating=Max('rating', filter=Exists(
|
||||
Book.authors.through.objects.filter(book=OuterRef('pk')),
|
||||
)),
|
||||
)
|
||||
self.assertEqual(aggregate, {'max_rating': 4.5})
|
||||
|
|
Loading…
Reference in New Issue