Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#15305 closed Bug (fixed)

GeoQuerySet with values() and aggregates raises exception

Reported by: vrehak Owned by: jbronn
Component: GIS Version: master
Severity: Normal Keywords:
Cc: milos.urbanek@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

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.

Attachments (3)

geoqueryset-values.diff (761 bytes) - added by vrehak 6 years ago.
geoq_agg.patch (2.5 KB) - added by milosu 6 years ago.
patch and related test case
15305.1.diff (1.5 KB) - added by jbronn 5 years ago.

Download all attachments as: .zip

Change History (10)

Changed 6 years ago by vrehak

Attachment: geoqueryset-values.diff added

comment:1 Changed 6 years ago by vrehak

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Summary: GeoQuerySet with values() raises exceptionGeoQuerySet with values() and aggregates raises exception

Changed 6 years ago by milosu

Attachment: geoq_agg.patch added

patch and related test case

comment:2 Changed 6 years ago by milosu

Cc: milos.urbanek@… added
Has patch: set

comment:3 Changed 6 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:4 Changed 6 years ago by Łukasz Rekucki

Severity: Normal
Type: Bug

comment:5 Changed 5 years ago by jbronn

Easy pickings: unset
milestone: 1.4
Owner: changed from nobody to jbronn
Patch needs improvement: set
Status: newassigned
UI/UX: unset

Changed 5 years ago by jbronn

Attachment: 15305.1.diff added

comment:6 Changed 5 years ago by jbronn

Resolution: fixed
Status: assignedclosed

In [16797]:

Fixed #15305 -- Made Count aggregate and .values() play nice together on GeoQuerySets. Thanks, vrehak for the bug report and milosu for initial patch.

comment:7 Changed 5 years ago by Jacob

milestone: 1.4

Milestone 1.4 deleted

Note: See TracTickets for help on using tickets.
Back to Top