[Django] #26112: Aggregate Sum of GIS Aggregates fails

25 views
Skip to first unread message

Django

unread,
Jan 21, 2016, 5:03:25 AM1/21/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+------------------------
Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: 1.9
Severity: Normal | Keywords: aggregates
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------
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 `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,
basically checking if the value is a float or int.

--
Ticket URL: <https://code.djangoproject.com/ticket/26112>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 21, 2016, 5:10:45 AM1/21/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+--------------------------------------

Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: 1.9
Severity: Normal | Resolution:

Keywords: aggregates | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by yellowcap):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> 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 `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,
> basically checking if the value is a float or int.

New description:

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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:1>

Django

unread,
Jan 21, 2016, 6:57:46 AM1/21/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+--------------------------------------

Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: 1.9
Severity: Normal | Resolution:

Keywords: aggregates | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Description changed by yellowcap:

Old description:

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

New description:

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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:2>

Django

unread,
Jan 21, 2016, 7:16:35 AM1/21/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+-------------------------------------

Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: 1.9
Severity: Normal | Resolution:
Keywords: aggregates | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

[https://github.com/django/django/pull/6004 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:3>

Django

unread,
Jan 21, 2016, 11:43:08 AM1/21/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+-------------------------------------

Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: 1.9
Severity: Normal | Resolution:
Keywords: aggregates | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------
Changes (by charettes):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:4>

Django

unread,
Jan 22, 2016, 11:16:37 AM1/22/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+---------------------------------------------

Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: aggregates | Triage Stage: Ready for checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------------------
Changes (by charettes):

* needs_better_patch: 1 => 0
* version: 1.9 => master
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:5>

Django

unread,
Jan 22, 2016, 1:40:38 PM1/22/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+---------------------------------------------
Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: closed
Component: GIS | Version: master
Severity: Normal | Resolution: fixed

Keywords: aggregates | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"a08d2463d2674b95f5a995f77cd9596168378a4f" a08d2463]:
{{{
#!CommitTicketReference repository=""
revision="a08d2463d2674b95f5a995f77cd9596168378a4f"
Fixed #26112 -- Error when computing aggregate of GIS areas.

Thanks Simon Charette and Claude Paroz for the reviews.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:6>

Django

unread,
Jan 23, 2016, 7:30:39 AM1/23/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+-------------------------------------

Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: aggregates | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------
Changes (by timgraham):

* status: closed => new
* has_patch: 1 => 0
* resolution: fixed =>
* stage: Ready for checkin => Accepted


Comment:

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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:7>

Django

unread,
Jan 25, 2016, 6:14:57 PM1/25/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+-------------------------------------

Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: aggregates | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------

Comment (by shaib):

Oracle-fixing [https://github.com/django/django/pull/6041 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:8>

Django

unread,
Jan 26, 2016, 2:35:10 PM1/26/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+-------------------------------------

Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: aggregates | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------
Changes (by shaib):

* has_patch: 0 => 1


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:9>

Django

unread,
Feb 9, 2016, 10:09:23 AM2/9/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+-------------------------------------

Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: aggregates | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"bb51dc902dc760b6fd03b860335fd99f47e2e13d" bb51dc9]:
{{{
#!CommitTicketReference repository=""
revision="bb51dc902dc760b6fd03b860335fd99f47e2e13d"
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.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:10>

Django

unread,
Feb 9, 2016, 10:09:37 AM2/9/16
to django-...@googlegroups.com
#26112: Aggregate Sum of GIS Aggregates fails
----------------------------+-------------------------------------
Reporter: yellowcap | Owner: yellowcap
Type: Bug | Status: closed
Component: GIS | Version: master
Severity: Normal | Resolution: fixed

Keywords: aggregates | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => fixed


--
Ticket URL: <https://code.djangoproject.com/ticket/26112#comment:11>

Reply all
Reply to author
Forward
0 new messages