Fixed #15305 -- Made `Count` aggregate and `.values()` play nice together on `GeoQuerySets`. Thanks, vrehak for the bug report and milosu for initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16797 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2918c3de74
commit
a25413bf86
|
@ -171,10 +171,6 @@ class GeoSQLCompiler(compiler.SQLCompiler):
|
||||||
"""
|
"""
|
||||||
values = []
|
values = []
|
||||||
aliases = self.query.extra_select.keys()
|
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
|
# Have to set a starting row number offset that is used for
|
||||||
# determining the correct starting row index -- needed for
|
# determining the correct starting row index -- needed for
|
||||||
|
|
|
@ -245,6 +245,13 @@ class RelatedGeoModelTest(TestCase):
|
||||||
self.assertEqual(1, len(vqs))
|
self.assertEqual(1, len(vqs))
|
||||||
self.assertEqual(3, vqs[0]['num_books'])
|
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.
|
# TODO: The phantom model does appear on Oracle.
|
||||||
@no_oracle
|
@no_oracle
|
||||||
def test13_select_related_null_fk(self):
|
def test13_select_related_null_fk(self):
|
||||||
|
|
Loading…
Reference in New Issue