Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e52657

Browse files
committed
Fixed #10594 -- GeoQuerySet measurment methods no longer crash on geometry fields with NULL values. Thanks, whiteinge for the bug report and yourcelf for the initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12885 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 381b10c commit 7e52657

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,20 @@ def clone(self, *args, **kwargs):
5151
return obj
5252

5353
def convert_values(self, value, field, connection):
54-
""" Using the same routines that Oracle does we can convert our
54+
"""
55+
Using the same routines that Oracle does we can convert our
5556
extra selection objects into Geometry and Distance objects.
5657
TODO: Make converted objects 'lazy' for less overhead.
5758
"""
5859
if connection.ops.oracle:
5960
# Running through Oracle's first.
6061
value = super(GeoQuery, self).convert_values(value, field or GeomField(), connection)
6162

62-
if isinstance(field, DistanceField):
63+
if value is None:
64+
# Output from spatial function is NULL (e.g., called
65+
# function on a geometry field with NULL value).
66+
pass
67+
elif isinstance(field, DistanceField):
6368
# Using the field's distance attribute, can instantiate
6469
# `Distance` with the right context.
6570
value = Distance(**{field.distance_att : value})

‎django/contrib/gis/tests/distapp/models.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ class CensusZipcode(models.Model):
2626
name = models.CharField(max_length=5)
2727
poly = models.PolygonField(srid=4269)
2828
objects = models.GeoManager()
29+
def __unicode__(self): return self.name
2930

3031
class SouthTexasZipcode(models.Model):
3132
"Model for a few South Texas ZIP codes."
3233
name = models.CharField(max_length=5)
33-
poly = models.PolygonField(srid=32140)
34+
poly = models.PolygonField(srid=32140, null=True)
3435
objects = models.GeoManager()
3536
def __unicode__(self): return self.name
3637

‎django/contrib/gis/tests/distapp/tests.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,17 @@ def test08_perimeter(self):
362362
for i, c in enumerate(SouthTexasCity.objects.perimeter(model_att='perim')):
363363
self.assertEqual(0, c.perim.m)
364364

365+
def test09_measurement_null_fields(self):
366+
"Testing the measurement GeoQuerySet methods on fields with NULL values."
367+
# Creating SouthTexasZipcode w/NULL value.
368+
SouthTexasZipcode.objects.create(name='78212')
369+
# Performing distance/area queries against the NULL PolygonField,
370+
# and ensuring the result of the operations is None.
371+
htown = SouthTexasCity.objects.get(name='Downtown Houston')
372+
z = SouthTexasZipcode.objects.distance(htown.point).area().get(name='78212')
373+
self.assertEqual(None, z.distance)
374+
self.assertEqual(None, z.area)
375+
365376
def suite():
366377
s = unittest.TestSuite()
367378
s.addTest(unittest.makeSuite(DistanceTest))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /