1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #30188 -- Fixed a crash when aggregating over a subquery annotation.

This commit is contained in:
Simon Charette
2019-03-08 11:26:53 -05:00
committed by Tim Graham
parent f19a4945e1
commit bdc07f176e
2 changed files with 15 additions and 2 deletions

View File

@@ -551,6 +551,19 @@ class BasicExpressionsTests(TestCase):
)
self.assertEqual(qs.get().float, 1.2)
@skipUnlessDBFeature('supports_subqueries_in_group_by')
def test_aggregate_subquery_annotation(self):
aggregate = Company.objects.annotate(
ceo_salary=Subquery(
Employee.objects.filter(
id=OuterRef('ceo_id'),
).values('salary')
),
).aggregate(
ceo_salary_gt_20=Count('pk', filter=Q(ceo_salary__gt=20)),
)
self.assertEqual(aggregate, {'ceo_salary_gt_20': 1})
def test_explicit_output_field(self):
class FuncA(Func):
output_field = models.CharField()