Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 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 3 years ago.
geoq_agg.patch (2.5 KB) - added by milosu 3 years ago.
patch and related test case
15305.1.diff (1.5 KB) - added by jbronn 3 years ago.

Download all attachments as: .zip

Change History (10)

Changed 3 years ago by vrehak

comment:1 Changed 3 years ago by vrehak

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from GeoQuerySet with values() raises exception to GeoQuerySet with values() and aggregates raises exception

Changed 3 years ago by milosu

patch and related test case

comment:2 Changed 3 years ago by milosu

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

comment:3 Changed 3 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 3 years ago by lrekucki

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 3 years ago by jbronn

  • Easy pickings unset
  • milestone set to 1.4
  • Owner changed from nobody to jbronn
  • Patch needs improvement set
  • Status changed from new to assigned
  • UI/UX unset

Changed 3 years ago by jbronn

comment:6 Changed 3 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed

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 3 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.