#31087: SpatialLite backend raises ValueError when getting distance parameter
--------------------------------------+------------------------
               Reporter:  tcourtqtm   |          Owner:  nobody
                   Type:  Bug         |         Status:  new
              Component:  GIS         |        Version:  2.2
               Severity:  Normal      |       Keywords:
           Triage Stage:  Unreviewed  |      Has patch:  0
    Needs documentation:  0           |    Needs tests:  0
Patch needs improvement:  0           |  Easy pickings:  0
                  UI/UX:  0           |
--------------------------------------+------------------------
 I'm experiencing a `ValueError` from the SpatiaLite backend. When doing a
 query like this:

 `MyModel.objects.filter(point__dwithin = (some_point,
 D(km=distance_in_km)))`

 I am getting this error:

 `ValueError: Only numeric values of degree units are allowed on geographic
 DWithin queries.`

 This does not happen with the PostGIS backend and I believe it's a bug.

 After a bit of searching I noticed that the difference between the two
 backends is that postgis has a conditional to check if the PointField is
 geographic and, if it is, avoids the exception.

 The
 
[https://github.com/django/django/blob/738e9e615dc81b561c9fb01439119f4475c2e25b/django/contrib/gis/db/backends/postgis/operations.py#L255
 code from the postgis backend]:

 {{{
         if isinstance(value, Distance):
             if geography:
                 dist_param = value.m
             elif geodetic:
                 if lookup_type == 'dwithin':
                     raise ValueError('Only numeric values of degree units
 are '
                                      'allowed on geographic DWithin
 queries.')
                 dist_param = value.m
             else:
                 dist_param = getattr(value,
 Distance.unit_attname(f.units_name(self.connection)))
 }}}

 And the
 
[https://github.com/django/django/blob/738e9e615dc81b561c9fb01439119f4475c2e25b/django/contrib/gis/db/backends/spatialite/operations.py#L131
 same function from the spatialite backend]:

 {{{
         if isinstance(value, Distance):
             if f.geodetic(self.connection):
                 if lookup_type == 'dwithin':
                     raise ValueError(
                         'Only numeric values of degree units are allowed
 on '
                         'geographic DWithin queries.'
                     )
                 dist_param = value.m
             else:
                 dist_param = getattr(value,
 Distance.unit_attname(f.units_name(self.connection)))
 }}}

 I am very unfamiliar with Geo stuff in general but this looks like a
 simple omission in the spatialite code. I believe it should have a similar
 `if geography` check.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31087>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.87aebc3e15cf435e2e94e392943e14ce%40djangoproject.com.

Reply via email to