Author: jbronn
Date: 2011-09-10 17:00:15 -0700 (Sat, 10 Sep 2011)
New Revision: 16797
Modified:
django/trunk/django/contrib/gis/db/models/sql/compiler.py
django/trunk/django/contrib/gis/tests/relatedapp/tests.py
Log:
Fixed #15305 -- Made `Count` aggregate and `.values()` play nice together on
`GeoQuerySets`. Thanks, vrehak for the bug report and milosu for initial patch.
Modified: django/trunk/django/contrib/gis/db/models/sql/compiler.py
===================================================================
--- django/trunk/django/contrib/gis/db/models/sql/compiler.py 2011-09-10
22:53:26 UTC (rev 16796)
+++ django/trunk/django/contrib/gis/db/models/sql/compiler.py 2011-09-11
00:00:15 UTC (rev 16797)
@@ -171,10 +171,6 @@
"""
values = []
aliases = self.query.extra_select.keys()
- if self.query.aggregates:
- # If we have an aggregate annotation, must extend the aliases
- # so their corresponding row values are included.
- aliases.extend([None for i in xrange(len(self.query.aggregates))])
# Have to set a starting row number offset that is used for
# determining the correct starting row index -- needed for
Modified: django/trunk/django/contrib/gis/tests/relatedapp/tests.py
===================================================================
--- django/trunk/django/contrib/gis/tests/relatedapp/tests.py 2011-09-10
22:53:26 UTC (rev 16796)
+++ django/trunk/django/contrib/gis/tests/relatedapp/tests.py 2011-09-11
00:00:15 UTC (rev 16797)
@@ -245,6 +245,13 @@
self.assertEqual(1, len(vqs))
self.assertEqual(3, vqs[0]['num_books'])
+ def test13c_count(self):
+ "Testing `Count` aggregate with `.values()`. See #15305."
+ qs =
Location.objects.filter(id=5).annotate(num_cities=Count('city')).values('id',
'point', 'num_cities')
+ self.assertEqual(1, len(qs))
+ self.assertEqual(2, qs[0]['num_cities'])
+ self.assertTrue(isinstance(qs[0]['point'], GEOSGeometry))
+
# TODO: The phantom model does appear on Oracle.
@no_oracle
def test13_select_related_null_fk(self):
@@ -284,7 +291,7 @@
def test16_annotated_date_queryset(self):
"Ensure annotated date querysets work if spatial backend is used. See
#14648."
- birth_years = [dt.year for dt in
+ birth_years = [dt.year for dt in
list(Author.objects.annotate(num_books=Count('books')).dates('dob', 'year'))]
birth_years.sort()
self.assertEqual([1950, 1974], birth_years)
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.