following test case fails:
from django.db.models import Q
from django.contrib.gis.db import models
class Area(models.Model):
poly = models.PolygonField(srid=4326, verbose_name=u"area repr")
objects = models.GeoManager()
class District(models.Model):
poly = models.PolygonField(srid=4326, verbose_name=u"district repr")
objects = models.GeoManager()
class Factory(models.Model):
area = models.ForeignKey(Area)
district = models.ForeignKey(District)
__test__ = {'API_TESTS':"""
>>> from django.contrib.gis.geos import fromstr
>>> location = fromstr('POINT (5 7)')
>>> a, created = Area.objects.get_or_create(poly=fromstr('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'))
>>> d, created = District.objects.get_or_create(poly=fromstr('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'))
>>> f, created = Factory.objects.get_or_create(area=a, district=d)
>>> areas = Area.objects.filter(poly__intersects = location)
>>> districts = District.objects.filter(poly__intersects = location)
>>> qobj = Q(area__isnull=True)&Q(district__isnull=True)
>>> qobj |= (Q(area__in = areas)|Q(district__in = districts))
>>> match = Factory.objects.filter(qobj)
>>> match2 = Factory.objects.filter(id__in = match)
>>> match2.count()
1
"""}
the last line will raise an exception in django.contrib.gis.db.backends.postgis.adapter eq due to the comparision against empty string
the following patch solves the problem:
Index: adapter.py
===================================================================
--- adapter.py (revision 3756)
+++ adapter.py (working copy)
@@ -21,6 +21,8 @@
raise Exception('Error implementing psycopg2 protocol. Is psycopg2 installed?')
def __eq__(self, other):
+ if not isinstance(other, PostGISAdapter):
+ return False
return (self.ewkb == other.ewkb) and (self.srid == other.srid)
def __str__(self):
Could you provide a single diff patch including the fix and tests? Could you also rewrite your tests using unittests since this is now the preferred way for django's test suite.