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

Refs #30188 -- Avoided GROUP BY when aggregating over non-aggregates.

This commit is contained in:
Simon Charette
2019-03-08 18:15:44 -05:00
committed by Tim Graham
parent d1e9c25162
commit 3f32154f40
2 changed files with 16 additions and 6 deletions

View File

@@ -551,7 +551,6 @@ class BasicExpressionsTests(TestCase):
)
self.assertEqual(qs.get().float, 1.2)
@skipUnlessDBFeature('supports_subqueries_in_group_by')
def test_aggregate_subquery_annotation(self):
with self.assertNumQueries(1) as ctx:
aggregate = Company.objects.annotate(
@@ -566,7 +565,11 @@ class BasicExpressionsTests(TestCase):
self.assertEqual(aggregate, {'ceo_salary_gt_20': 1})
# Aggregation over a subquery annotation doesn't annotate the subquery
# twice in the inner query.
self.assertLessEqual(ctx.captured_queries[0]['sql'].count('SELECT'), 4,)
sql = ctx.captured_queries[0]['sql']
self.assertLessEqual(sql.count('SELECT'), 3)
# GROUP BY isn't required to aggregate over a query that doesn't
# contain nested aggregates.
self.assertNotIn('GROUP BY', sql)
def test_explicit_output_field(self):
class FuncA(Func):