Opened 8 years ago

Closed 7 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


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" %

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/", line 107, in _result_iter
  File "/usr/lib/pymodules/python2.7/django/db/models/", line 772, in _fill_cache
  File "/usr/lib/pymodules/python2.7/django/db/models/", line 273, in iterator
    for row in compiler.results_iter():
  File "/usr/lib/pymodules/python2.7/django/db/models/sql/", line 680, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/lib/pymodules/python2.7/django/db/models/sql/", line 725, in execute_sql
    sql, params = self.as_sql()
  File "/usr/lib/pymodules/python2.7/django/db/models/sql/", 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/", line 92, in as_sql
    sql, params = child.as_sql(qn=qn, connection=connection)
  File "/usr/lib/pymodules/python2.7/django/db/models/sql/", 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/", line 50, in make_atom
    return super(GeoWhereNode, self).make_atom(child, qn, connection)
  File "/usr/lib/pymodules/python2.7/django/db/models/sql/", 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/", 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: 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:

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 Changed 8 years ago by Aymeric Augustin

Component: Database layer (models, ORM)GIS
Triage Stage: UnreviewedAccepted

Yes, given the traceback, it's probably a bug.

comment:2 Changed 8 years ago by jpk

Cc: jpk added

comment:3 Changed 7 years ago by Claude Paroz

Resolution: duplicate
Status: newclosed

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.

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