#32358 closed Bug (fixed)
Paginating a queryset with a distance lookup fails due to unhashable type Distance
| Reported by: | Illia Volochii | Owned by: | nobody |
|---|---|---|---|
| Component: | GIS | Version: | dev |
| Severity: | Normal | Keywords: | distance |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
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':
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
Attachments (1)
Change History (8)
by , 5 years ago
| Attachment: | traceback.txt added |
|---|
comment:1 by , 5 years ago
| Easy pickings: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Version: | 2.2 → master |
comment:2 by , 5 years ago
Paginator issue is fixed, but you can still encounter this issue when grouping by annotation with Distance().
comment:7 by , 5 years ago
Per our supported versions policy, 2.2 is only receiving fixes for security and data loss issues.
MeasureBaseis clearly missing a__hash__method.