Opened 13 years ago
Closed 12 years ago
#17314 closed Bug (duplicate)
Error creating nested query with GeoDjango's spatial filters
Reported by: | jpk | Owned by: | nobody |
---|---|---|---|
Component: | GIS | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | jpk | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
With the following models:
from django.contrib.gis.db import models class Spot(models.Model): objects = models.GeoManager() location = models.PointField(srid=4326, spatial_index=True) def __unicode__(self): return "id: %s" % self.id class Property(models.Model): objects = models.GeoManager() spot = models.ForeignKey(Spot) def __unicode__(self): return "belonging to Spot %s" % self.spot_id
And using, for example, the following filters:
spots = Spot.objects.filter(location__contained=Polygon(( (-180,90),(180,90),(180,0),(-180,0),(-180,90) )) ) props = Property.objects.filter(spot__in=spots)
And trying to iterate over props, causes the following error:
>>> for p in props: ... print p ... Traceback (most recent call last): File "<console>", line 1, in <module> File "/usr/lib/pymodules/python2.7/django/db/models/query.py", line 107, in _result_iter self._fill_cache() File "/usr/lib/pymodules/python2.7/django/db/models/query.py", line 772, in _fill_cache self._result_cache.append(self._iter.next()) File "/usr/lib/pymodules/python2.7/django/db/models/query.py", line 273, in iterator for row in compiler.results_iter(): File "/usr/lib/pymodules/python2.7/django/db/models/sql/compiler.py", line 680, in results_iter for rows in self.execute_sql(MULTI): File "/usr/lib/pymodules/python2.7/django/db/models/sql/compiler.py", line 725, in execute_sql sql, params = self.as_sql() File "/usr/lib/pymodules/python2.7/django/db/models/sql/compiler.py", line 68, in as_sql where, w_params = self.query.where.as_sql(qn=qn, connection=self.connection) File "/usr/lib/pymodules/python2.7/django/db/models/sql/where.py", line 92, in as_sql sql, params = child.as_sql(qn=qn, connection=connection) File "/usr/lib/pymodules/python2.7/django/db/models/sql/where.py", line 95, in as_sql sql, params = self.make_atom(child, qn, connection) File "/usr/lib/pymodules/python2.7/django/contrib/gis/db/models/sql/where.py", line 50, in make_atom return super(GeoWhereNode, self).make_atom(child, qn, connection) File "/usr/lib/pymodules/python2.7/django/db/models/sql/where.py", line 166, in make_atom if (len(params) == 1 and params[0] == '' and lookup_type == 'exact' File "/usr/lib/pymodules/python2.7/django/contrib/gis/db/backends/postgis/adapter.py", line 24, in __eq__ return (self.ewkb == other.ewkb) and (self.srid == other.srid) AttributeError: 'str' object has no attribute 'ewkb'
A full paste of me reproducing the error in the python shell here: http://pastebin.com/fBySTUD0 I also have a little test project I used to reproduce this. I can post it somewhere if needed.
Doing the same thing without using a spatial filter works fine. Being new to django, I assumed I was doing something wrong, but after a conversation in the #geodjango channel, it was concluded that this is probably a bug in the ORM. There's a paste of that conversation here: http://pastebin.com/bwZYVa6j
System information (everything installed from ubuntu's packages):
- Ubuntu 11.10
- Python 2.7.2
- Django 1.3.0
- PostgreSQL 9.1.1
- PostGIS 1.5.3
Change History (3)
comment:1 by , 13 years ago
Component: | Database layer (models, ORM) → GIS |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 13 years ago
Cc: | added |
---|
comment:3 by , 12 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I guess this is a duplicate of #13670 which has been fixed in 1.4. Please reopen if you can reproduce it with 1.4.
Yes, given the traceback, it's probably a bug.