When I apply the attached patch to contrib.gis testsuite and run it on r15540 with Python 2.6 and PostGis I get the following exception:
======================================================================
ERROR: test12a_count (django.contrib.gis.tests.relatedapp.tests.RelatedGeoModelTest)
Testing `Count` aggregate use with the `GeoManager` on geo-fields.
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python26\lib\site-packages\django_versions\trunk\django\contrib\gis\tests\relatedapp\tests.py", line 236, in test12a_count
len(locqs)
File "C:\Python26\lib\site-packages\django_versions\trunk\django\db\models\query.py", line 82, in __len__
self._result_cache = list(self.iterator())
File "C:\Python26\lib\site-packages\django_versions\trunk\django\db\models\query.py", line 841, in iterator
for row in self.query.get_compiler(self.db).results_iter():
File "C:\Python26\lib\site-packages\django_versions\trunk\django\db\models\sql\compiler.py", line 698, in results_iter
row = self.resolve_columns(row, fields)
File "C:\Python26\lib\site-packages\django_versions\trunk\django\contrib\gis\db\models\sql\compiler.py", line 197, in resolve_columns
values.append(self.query.convert_values(value, field, connection=self.connection))
File "C:\Python26\lib\site-packages\django_versions\trunk\django\contrib\gis\db\models\sql\query.py", line 74, in convert_values
value = Geometry(value)
File "C:\Python26\lib\site-packages\django_versions\trunk\django\contrib\gis\geos\geometry.py", line 85, in __init__
raise TypeError('Improper geometry input type: %s' % str(type(geo_input)))
TypeError: Improper geometry input type: <type 'long'>
----------------------------------------------------------------------
The exception disappears if I comment out adding of aggregates to aliases in compiler.py like this
--- django/contrib/gis/db/models/sql/compiler.py (revision 15540)
+++ django/contrib/gis/db/models/sql/compiler.py (working copy)
@@ -171,10 +171,10 @@
"""
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))])
+ #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
I have not tried for a proper fix as I believe it requires testing with Oracle.
patch and related test case