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

[1.8.x] Fixed #25377 -- Changed Count queries to execute COUNT(*) instead of COUNT('*').

Backport of 3fe3887a2e from master
This commit is contained in:
Adam Chainz
2015-09-10 17:07:09 +01:00
committed by Tim Graham
parent 69017bade0
commit 3c2c74f58f
6 changed files with 33 additions and 14 deletions

View File

@@ -306,6 +306,12 @@ class BaseAggregateTestCase(TestCase):
vals = Book.objects.aggregate(Count("rating", distinct=True))
self.assertEqual(vals, {"rating__count": 4})
def test_count_star(self):
with self.assertNumQueries(1) as ctx:
Book.objects.aggregate(n=Count("*"))
sql = ctx.captured_queries[0]['sql']
self.assertIn('SELECT COUNT(*) ', sql)
def test_fkey_aggregate(self):
explicit = list(Author.objects.annotate(Count('book__id')))
implicit = list(Author.objects.annotate(Count('book')))