Opened 8 years ago

Last modified 8 years ago

#26112 closed Bug

Aggregate Sum of GIS Aggregates fails — at Version 2

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 Daniel Wiesmann)

There is an error when trying to compute a regular aggregate value from a GIS Area 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

Country.objects.annotate(areasum=Sum(Area('mpoly')))

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 Area 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.

Change History (2)

comment:1 by Daniel Wiesmann, 8 years ago

Description: modified (diff)

comment:2 by Daniel Wiesmann, 8 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top