Loading django/db/models/sql/aggregates.py +1 −1 Original line number Diff line number Diff line Loading @@ -79,7 +79,7 @@ class Aggregate(object): elif isinstance(self.col, (list, tuple)): field_name = '.'.join(qn(c) for c in self.col) else: field_name = self.col field_name = qn(self.col) substitutions = { 'function': self.sql_function, Loading tests/aggregation_regress/tests.py +10 −0 Original line number Diff line number Diff line Loading @@ -1114,3 +1114,13 @@ class AggregationTests(TestCase): self.assertQuerysetEqual( qs, ['Sams Teach Yourself Django in 24 Hours'], lambda b: b.name) def test_annotate_reserved_word(self): """ Regression #18333 - Ensure annotated column name is properly quoted. """ vals = Book.objects.annotate(select=Count('authors__id')).aggregate(Sum('select'), Avg('select')) self.assertEqual(vals, { 'select__sum': 10, 'select__avg': Approximate(1.666, places=2), }) Loading
django/db/models/sql/aggregates.py +1 −1 Original line number Diff line number Diff line Loading @@ -79,7 +79,7 @@ class Aggregate(object): elif isinstance(self.col, (list, tuple)): field_name = '.'.join(qn(c) for c in self.col) else: field_name = self.col field_name = qn(self.col) substitutions = { 'function': self.sql_function, Loading
tests/aggregation_regress/tests.py +10 −0 Original line number Diff line number Diff line Loading @@ -1114,3 +1114,13 @@ class AggregationTests(TestCase): self.assertQuerysetEqual( qs, ['Sams Teach Yourself Django in 24 Hours'], lambda b: b.name) def test_annotate_reserved_word(self): """ Regression #18333 - Ensure annotated column name is properly quoted. """ vals = Book.objects.annotate(select=Count('authors__id')).aggregate(Sum('select'), Avg('select')) self.assertEqual(vals, { 'select__sum': 10, 'select__avg': Approximate(1.666, places=2), })