#10594 closed (fixed)
GeoQuerySet methods should filter out NULL values by default
Reported by: | Nathaniel Whiteinge | Owned by: | jbronn |
---|---|---|---|
Component: | GIS | Version: | dev |
Severity: | Keywords: | distance queryset | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Given the following GIS model:
class SomeModel(models.Model): location = models.PointField(null=True) <snip>
When populated with instances that both have and do not have location information, doing a distance(geom)
query yields unexpected results.
For example, SomeModel.objects.distance(somePoint)
returns no results at all. SomeModel.objects.filter(location__isnull=False).distance(somePoint)
works as expected.
IMO, distance(geom)
results that cannot calculate distance should simply return None.
Attachments (2)
Change History (7)
by , 16 years ago
Attachment: | fix_null_geometry_querysets.diff added |
---|
comment:1 by , 16 years ago
Has patch: | set |
---|
The problem seems to arise from line 49 in django/contrib/gis/measure.py
if not isinstance(value, float): value = float(value)
Where "value" is the value of the geometry field. If the field is null, this becomes None, and propagates a ValueError up the stack resulting in an empty queryset.
I'm attaching a patch which fixes this by altering the method which constructs geometry objects out of the measurement attributes to instead keep the attribute as "None" if the value is None.
by , 16 years ago
Attachment: | fix_null_geometry_querysets_with_tests.diff added |
---|
Updated diff that includes tests
comment:2 by , 16 years ago
milestone: | → 1.2 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Summary: | distance(geom) results ambiguous when the PointField can be null → GeoQuerySet methods should filter out NULL values by default |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Prevent null geometry fields from resulting in empty querysets