Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18333 - Quoted annotated column names

  • Loading branch information...
commit 9a041807fcde7ff7245696a743196d31ec7c7b5c 1 parent 77f6b46
Michael Manfre manfre authored timgraham committed
2  django/db/models/sql/aggregates.py
View
@@ -79,7 +79,7 @@ def as_sql(self, qn, connection):
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,
10 tests/aggregation_regress/tests.py
View
@@ -1114,3 +1114,13 @@ def test_fobj_group_by(self):
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),
+ })
Please sign in to comment.
Something went wrong with that request. Please try again.