Opened 16 years ago

Closed 15 years ago

Last modified 13 years ago

#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)

fix_null_geometry_querysets.diff (610 bytes ) - added by Charlie DeTar 16 years ago.
Prevent null geometry fields from resulting in empty querysets
fix_null_geometry_querysets_with_tests.diff (3.0 KB ) - added by Charlie DeTar 16 years ago.
Updated diff that includes tests

Download all attachments as: .zip

Change History (7)

by Charlie DeTar, 16 years ago

Prevent null geometry fields from resulting in empty querysets

comment:1 by Charlie DeTar, 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 Charlie DeTar, 16 years ago

Updated diff that includes tests

comment:2 by jbronn, 16 years ago

milestone: 1.2
Owner: changed from nobody to jbronn
Status: newassigned
Summary: distance(geom) results ambiguous when the PointField can be nullGeoQuerySet methods should filter out NULL values by default
Triage Stage: UnreviewedAccepted

comment:3 by jbronn, 15 years ago

Resolution: fixed
Status: assignedclosed

(In [12885]) 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.

comment:4 by jbronn, 15 years ago

(In [12886]) [1.1.X] 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.

Backport of r12885 from trunk.

comment:5 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top