#32358: Paginating a queryset with a distance lookup fails due to unhashable
type
Distance
------------------------------------------+--------------------------
Reporter: Illia Volochii | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 2.2
Severity: Normal | Keywords: distance
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------+--------------------------
There is a model with a `location = models.PointField()` field.
Django 2.2.17 fails to paginate such a queryset because of `TypeError:
unhashable type: 'Distance'`:
{{{
#!python
from django.contrib.gis.geos import Point
from django.contrib.gis.measure import Distance
from django.core.paginator import Paginator
from django.db.models import Case, IntegerField, Q, Value, When
point = Point(0, 0)
cities = City.objects.annotate(
relative_distance=Case(
When(Q(location__distance_lte=(point, Distance(mi=100))),
then=Value(100)),
default=Value(1000),
output_field=IntegerField(),
),
)
Paginator(cities, 10).page(1)
}}}
This code works well with Django 1.11 and the latest development version.
For those who have faced this bug too, it is possible to use
`Distance(mi=100).m` that is a hashable float in the lookup.
I attached a file with a full exception taceback.
Thanks,
Illia
--
Ticket URL: <https://code.djangoproject.com/ticket/32358>
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/050.b5b60ac402f52d36b6e9d89342229670%40djangoproject.com.