Opened 10 years ago
Last modified 10 years ago
#26112 closed Bug
Aggregate Sum of GIS Aggregates fails — at Version 1
| Reported by: | Daniel Wiesmann | Owned by: | Daniel Wiesmann |
|---|---|---|---|
| Component: | GIS | Version: | dev |
| Severity: | Normal | Keywords: | aggregates |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
There is an error when trying to compute a regular aggregate value from a GIS aggregate output. To take an example from the GIS geoapp tests, the following query fails.
from django.db.models import Sum
from django.contrib.gis.db.models.functions import Area, Intersection
Country.objects.annotate(intersum=Sum(Area(Intersection('mpoly', geom))))
I tracked this down to the from_db_value function in the GeometryField class here:
https://github.com/django/django/blob/master/django/contrib/gis/db/models/fields.py#L259
The problem seems to be that the Sum function returns a float, but the field is expecting a value that can be converted to a Geometry.
I'll open a pull request with a regression test and a proposed solution, basically checking if the value is a float or int.