Ticket #10594: fix_null_geometry_querysets_with_tests.diff

File fix_null_geometry_querysets_with_tests.diff, 3.0 KB (added by Charlie DeTar, 15 years ago)

Updated diff that includes tests

  • django/contrib/gis/db/models/sql/query.py

     
    233233        extra selection objects into Geometry and Distance objects.
    234234        TODO: Make converted objects 'lazy' for less overhead.
    235235        """
     236        if value == None:
     237            return value
     238
    236239        if SpatialBackend.oracle:
    237240            # Running through Oracle's first.
    238241            value = super(GeoQuery, self).convert_values(value, field or GeomField())
  • django/contrib/gis/tests/distapp/tests.py

     
    88from django.contrib.gis.tests.utils import oracle, postgis, spatialite, no_oracle, no_spatialite
    99
    1010from models import AustraliaCity, Interstate, SouthTexasInterstate, \
    11     SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode
     11    SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode, NullPointModel
    1212from data import au_cities, interstates, stx_interstates, stx_cities, stx_zips
    1313
    1414class DistanceTest(unittest.TestCase):
     
    203203            for i, z in enumerate(qs):
    204204                self.assertAlmostEqual(z.distance.m, dists_m[i], 5)
    205205
     206    def test03d_distance_method(self):
     207        "Testing the `distance` GeoQuerySet method with null geometries in models"
     208        # Ensure that null geometry fields in distance method lookups don't kill the
     209        # querysets (ticket #10594)
     210        null = NullPointModel.objects.create(name="Null")
     211        notnull = NullPointModel.objects.create(name="Not null", point=Point(0, 0))
     212        qs = NullPointModel.objects.distance(Point(0, 0))
     213        self.assertTrue(null in qs)
     214        self.assertTrue(notnull in qs)
     215        for obj in qs:
     216            if obj.name == "Null":
     217                self.assertEquals(obj.distance, None)
     218            elif obj.name == "Not null":
     219                self.assertEquals(obj.distance.m, 0)
     220
    206221    def test04_distance_lookups(self):
    207222        "Testing the `distance_lt`, `distance_gt`, `distance_lte`, and `distance_gte` lookup types."
    208223        # Retrieving the cities within a 20km 'donut' w/a 7km radius 'hole'
  • django/contrib/gis/tests/distapp/models.py

     
    4747    path = models.LineStringField(srid=32140)
    4848    objects = models.GeoManager()
    4949    def __unicode__(self): return self.name
     50
     51class NullPointModel(models.Model):
     52    name = models.CharField(max_length=30)
     53    point = models.PointField(null=True)
     54    objects = models.GeoManager()
     55    def __unicode__(self): return self.name
Back to Top