2

I'm having trouble constructing nested queries using in field lookup in GeoDjango. The following code demonstrates the problem:

inner_qs = Footprint.objects.filter(geom__bboverlaps=bounding_box)
outer_qs = Footprint.objects.filter(pk__in=inner_qs)
outer_qs.count()
# error

With the above code, the follow exception occurs:

if (len(params) == 1 and params[0] == '' and lookup_type == 'exact'
  File "../python2.6/site-packages/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'

(Here is the complete stack trace)

It appears that the error occurs whenever the inner query contains a spatial filter. The following nested query works fine though:

inner_qs = Footprint.objects.filter(frequency__gt=1)
outer_qs = Footprint.objects.filter(pk__in=inner_qs)
outer_qs.count()
# ok

Any idea what causes the problem?

ejel
  • 4,135
  • 9
  • 32
  • 39
  • Get the same error calling Q.exists() on empty geoqueryset... geodjango is great but really strange sometimes. Will post something if I can find the cause – Pill Jul 22 '11 at 13:10
  • Was dancing around it for quite some time. In 5 mins after posting comment realized that stupidly forgot to add GeoManager... ) – Pill Jul 22 '11 at 13:19
  • How did you fix your error? You mean you forgot to add `objects = models.GeoManager()` in your model class? – ejel Jul 22 '11 at 16:16
  • Yes - i was using custom manager inherited from standart manager. – Pill Jul 23 '11 at 13:04

0 Answers0