Are distance lookups available for MySQL or not?

78 views
Skip to first unread message

Clara Daia

unread,
Jan 2, 2019, 1:34:11 PM1/2/19
to Django users
Hello, everybody

I am using Django 2.1 with MariaDB 10.3.
I have been trying to get the 'dwithin' lookup to work on a PointField, but I keep getting the following error:

  ...
 
File "/usr/local/lib/python3.6/site-packages/django/contrib/gis/db/models/lookups.py", line 74, in get_rhs_op
   
return connection.ops.gis_operators[self.lookup_name]
KeyError: 'dwithin'

(To be more precise, I am using this filter backend from a library, which generates the lookup for me.)

Looking at the docs, I get conflicting info:

* this section says "Availability: PostGIS, Oracle, SpatiaLite, PGRaster (Native)", implying 'not available on MySQL'
* this other section says MySQL support was added on Django 2.0

I could switch to PostgreSQL as a last resort, but maybe I'm just forgetting some configuration? Are the distance lookups available for MySQL or not?

Best regards,

Clara

Clara Daia

unread,
Jan 2, 2019, 2:19:46 PM1/2/19
to Django users
I wrote the query myself in case the library was messing it up and got the same error:
self.assertEqual(MyModel.objects.filter(
geopositionfield__dwithin=(
Point(-25.427855, -49.279644),
0.00028321143293561684)
).count(), 1)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e1452b84-a33f-4121-a329-1aa03f818bf0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason

unread,
Jan 2, 2019, 9:00:20 PM1/2/19
to Django users
https://mariadb.com/kb/en/library/mysqlmariadb-spatial-support-matrix/ seems to be a good resource for mariadb gis functions, and as you can see, there's no listing for dwithin.  so while there might be support for mysql, it probably doesn't extend to mariadb

Clara Daia

unread,
Jan 3, 2019, 7:39:19 AM1/3/19
to Django users
Hello, Jason

I appreciate your help, and I tried running the test with a MySQL container but got the same error.
The MySQL spatial reference does not have a'dwithin' entry or similar either.

I changed my query to
self.assertEqual(MyModel.objects.filter(
geopositionfield__distance_lt=(

Point(-25.427855, -49.279644),
0.00028321143293561684)
).count(), 1)
And it seems to have worked, both on the MySQL and the MariaDB containers.
I suppose there is limited support and the documentation should specify which distance functions are available for MySQL. Do you think I should file a ticket?

Best regards,

Clara

Clara Daia

unread,
Jan 3, 2019, 7:43:06 AM1/3/19
to Django users

Jason

unread,
Jan 3, 2019, 10:15:17 AM1/3/19
to Django users
nice job in finding the cause and +1 for posting the compatibility table link here for future search reference.


Reply all
Reply to author
Forward
0 new messages