﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31087	SpatialLite backend raises ValueError when getting distance parameter.	tcourtqtm	nobody	"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."	Bug	closed	GIS	3.0	Normal	invalid			Unreviewed	0	0	0	0	0	0
