#29416: Undesired subquery added to the GROUP BY clause
-------------------------------------+-------------------------------------
     Reporter:  Antoine Pinsard      |                    Owner:  felixxm
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  2.0
  (models, ORM)                      |
     Severity:  Release blocker      |               Resolution:
     Keywords:  groupby, subquery    |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by felixxm):

 IMO query in this test  (even if we add
 "`ST_Distance(geoapp_multifields.point, ST_GeomFromText('POINT (-95.363151
 29.763374)'))`" to the GROUP BY clause) doesn't have much sense. This is
 not a realistic use case. It also didn't work before
 1d070d027c218285b66c0bde8079034b33a87f11.
 {{{
 #!sql
 SELECT
     `geoapp_city`.`name`,
     ST_Distance(`geoapp_multifields`.`point`, ST_GeomFromText('POINT
 (-95.363151 29.763374)')) AS `distance`,
     COUNT(`geoapp_multifields`.`id`) AS `count`
 FROM `geoapp_city`
 LEFT OUTER JOIN `geoapp_multifields` ON (`geoapp_city`.`id` =
 `geoapp_multifields`.`city_id`)
 GROUP BY `geoapp_city`.`id`
 ORDER BY `geoapp_city`.`id` ASC
 LIMIT 1
 }}}

 We can fix this test by changing:

 {{{
 diff --git a/tests/gis_tests/geoapp/test_expressions.py
 b/tests/gis_tests/geoapp/test_expressions.py
 index 2d0ebbcae0..89e83a782f 100644
 --- a/tests/gis_tests/geoapp/test_expressions.py
 +++ b/tests/gis_tests/geoapp/test_expressions.py
 @@ -3,7 +3,7 @@ from unittest import skipUnless
  from django.contrib.gis.db.models import F, GeometryField, Value,
 functions
  from django.contrib.gis.geos import Point, Polygon
  from django.db import connection
 -from django.db.models import Count
 +from django.db.models import Count, Min
  from django.test import TestCase, skipUnlessDBFeature

  from ..utils import postgis
 @@ -56,7 +56,7 @@ class GeoExpressionsTests(TestCase):
              poly=Polygon(((1, 1), (1, 2), (2, 2), (2, 1), (1, 1))),
          )
          qs = City.objects.values('name').annotate(
 -            distance=functions.Distance('multifields__point',
 multi_field.city.point),
 +            distance=Min(functions.Distance('multifields__point',
 multi_field.city.point)),
          ).annotate(count=Count('multifields'))
          self.assertTrue(qs.first())
 }}}

 or by adding `multifields__point` to the `values`, i.e.
 `City.objects.values('name', 'multifields__point')`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29416#comment:18>
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/066.0bac2653a2e02a66ef9574a33e0f1763%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to