Loading django/db/models/query.py +0 −1 Original line number Diff line number Diff line Loading @@ -319,7 +319,6 @@ class QuerySet(object): query.add_aggregate(aggregate_expr, self.model, alias, is_summary=True) aggregate_names.append(alias) query.append_aggregate_mask(aggregate_names) return query.get_aggregation(using=self.db) Loading django/db/models/sql/query.py +3 −0 Original line number Diff line number Diff line Loading @@ -321,6 +321,7 @@ class Query(object): # information but retrieves only the first row. Aggregate # over the subquery instead. if self.group_by is not None: from django.db.models.sql.subqueries import AggregateQuery query = AggregateQuery(self.model) Loading Loading @@ -996,6 +997,8 @@ class Query(object): field_name = field_list[0] source = opts.get_field(field_name) col = field_name # We want to have the alias in SELECT clause even if mask is set. self.append_aggregate_mask([alias]) # Add the aggregate to the query aggregate.add_to_query(self, alias, col=col, source=source, is_summary=is_summary) Loading tests/aggregation_regress/tests.py +7 −0 Original line number Diff line number Diff line Loading @@ -250,6 +250,13 @@ class AggregationTests(TestCase): 'price__max': Decimal("82.80") }) # Regression for #15624 - Missing SELECT columns when using values, annotate # and aggregate in a single query self.assertEqual( Book.objects.annotate(c=Count('authors')).values('c').aggregate(Max('c')), {'c__max': 3} ) def test_field_error(self): # Bad field requests in aggregates are caught and reported self.assertRaises( Loading Loading
django/db/models/query.py +0 −1 Original line number Diff line number Diff line Loading @@ -319,7 +319,6 @@ class QuerySet(object): query.add_aggregate(aggregate_expr, self.model, alias, is_summary=True) aggregate_names.append(alias) query.append_aggregate_mask(aggregate_names) return query.get_aggregation(using=self.db) Loading
django/db/models/sql/query.py +3 −0 Original line number Diff line number Diff line Loading @@ -321,6 +321,7 @@ class Query(object): # information but retrieves only the first row. Aggregate # over the subquery instead. if self.group_by is not None: from django.db.models.sql.subqueries import AggregateQuery query = AggregateQuery(self.model) Loading Loading @@ -996,6 +997,8 @@ class Query(object): field_name = field_list[0] source = opts.get_field(field_name) col = field_name # We want to have the alias in SELECT clause even if mask is set. self.append_aggregate_mask([alias]) # Add the aggregate to the query aggregate.add_to_query(self, alias, col=col, source=source, is_summary=is_summary) Loading
tests/aggregation_regress/tests.py +7 −0 Original line number Diff line number Diff line Loading @@ -250,6 +250,13 @@ class AggregationTests(TestCase): 'price__max': Decimal("82.80") }) # Regression for #15624 - Missing SELECT columns when using values, annotate # and aggregate in a single query self.assertEqual( Book.objects.annotate(c=Count('authors')).values('c').aggregate(Max('c')), {'c__max': 3} ) def test_field_error(self): # Bad field requests in aggregates are caught and reported self.assertRaises( Loading