Opened 8 years ago

Closed 8 years ago

#26112 closed Bug (fixed)

Aggregate Sum of GIS Aggregates fails

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 (11)

comment:1 by Daniel Wiesmann, 8 years ago

Description: modified (diff)

comment:2 by Daniel Wiesmann, 8 years ago

Description: modified (diff)

comment:3 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Simon Charette, 8 years ago

Patch needs improvement: set

comment:5 by Simon Charette, 8 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin
Version: 1.9master

comment:6 by Claude Paroz <claude@…>, 8 years ago

Resolution: fixed
Status: newclosed

In a08d2463:

Fixed #26112 -- Error when computing aggregate of GIS areas.

Thanks Simon Charette and Claude Paroz for the reviews.

comment:7 by Tim Graham, 8 years ago

Has patch: unset
Resolution: fixed
Status: closednew
Triage Stage: Ready for checkinAccepted

The new test fails on Oracle:

  File "/home/tim/code/django/tests/gis_tests/geoapp/test_functions.py", line 243, in test_area_with_regular_aggregate
    for c in qs:
...
ORA-22901: cannot compare VARRAY or LOB attributes of an object type

comment:8 by Shai Berger, 8 years ago

Oracle-fixing PR

comment:9 by Shai Berger, 8 years ago

Has patch: set

When I submitted the PR I was doubtful about it being the right solution, but now I've convinced myself that it is.

comment:10 by Tim Graham <timograham@…>, 8 years ago

In bb51dc9:

Refs #26112 -- Fixed aggregate GIS test on Oracle.

Made sure the test doesn't try to aggregate over MultiPolygonField and made
AreaField turn decimals into floats on the way from the DB.

Thanks Daniel Wiesmann, Jani Tiainen, and Tim Graham for review and discussion.

comment:11 by Tim Graham, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top