#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.28bc5a14f152c68c222088594b664824%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to