Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13670 -- Comparisons with the spatial adapter won't blow up in…

… some corner cases. Thanks, milosu for the bug report and jpaulett for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16757 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0516ac3d28a7ac8b756ada0e6f89473c7a6e0474 1 parent e061b03
Justin Bronn authored
2  django/contrib/gis/db/backends/adapter.py
@@ -8,6 +8,8 @@ def __init__(self, geom):
8 8
         self.srid = geom.srid
9 9
 
10 10
     def __eq__(self, other):
  11
+        if not isinstance(other, WKTAdapter):
  12
+            return False
11 13
         return self.wkt == other.wkt and self.srid == other.srid
12 14
 
13 15
     def __str__(self):
2  django/contrib/gis/db/backends/postgis/adapter.py
@@ -21,6 +21,8 @@ def __conform__(self, proto):
21 21
             raise Exception('Error implementing psycopg2 protocol. Is psycopg2 installed?')
22 22
 
23 23
     def __eq__(self, other):
  24
+        if not isinstance(other, PostGISAdapter):
  25
+            return False
24 26
         return (self.ewkb == other.ewkb) and (self.srid == other.srid)
25 27
 
26 28
     def __str__(self):
12  django/contrib/gis/tests/geoapp/test_regress.py
@@ -2,7 +2,7 @@
2 2
 from django.contrib.gis.tests.utils import no_mysql, no_spatialite
3 3
 from django.contrib.gis.shortcuts import render_to_kmz
4 4
 from django.test import TestCase
5  
-from models import City, PennsylvaniaCity
  5
+from models import City, PennsylvaniaCity, State
6 6
 
7 7
 class GeoRegressionTests(TestCase):
8 8
 
@@ -43,3 +43,13 @@ def test04_unicode_date(self):
43 43
         mansfield = PennsylvaniaCity.objects.create(name='Mansfield', county='Tioga', point='POINT(-77.071445 41.823881)',
44 44
                                                     founded=founded)
45 45
         self.assertEqual(founded, PennsylvaniaCity.objects.dates('founded', 'day')[0])
  46
+
  47
+    def test05_empty_count(self):
  48
+         "Testing that PostGISAdapter.__eq__ does check empty strings, see #13670"
  49
+         # contrived example, but need a geo lookup paired with an id__in lookup
  50
+         pueblo = City.objects.get(name='Pueblo')
  51
+         state = State.objects.filter(poly__contains=pueblo.point)
  52
+         cities_within_state = City.objects.filter(id__in=state)
  53
+
  54
+         # .count() should not throw TypeError in __eq__
  55
+         self.assertEqual(cities_within_state.count(), 1)

0 notes on commit 0516ac3

Please sign in to comment.
Something went wrong with that request. Please try again.