1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #33262 -- Fixed crash of conditional aggregation on Exists().

This commit is contained in:
Hannes Ljungberg 2021-11-03 15:34:37 +01:00 committed by Mariusz Felisiak
parent 25157033e9
commit a934d377af
3 changed files with 10 additions and 2 deletions

View File

@ -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):

View File

@ -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

View File

@ -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})