#11293: Filters on aggregates lose connector
-------------------------------------+-------------------------------------
     Reporter:  django@…             |                    Owner:  -
         Type:  Bug                  |                   Status:  reopened
    Component:  ORM aggregation      |                  Version:  1.4
     Severity:  Normal               |               Resolution:
     Keywords:  having, where,       |             Triage Stage:  Accepted
  aggregate, connector               |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by akaariai):

 Are you sure about not doing some typo in the test? The result seems
 really surprising to me. Here is my test results:
 {{{
 akaariai@akaariai-UX31E:~/Programming/django/django_test/django$ git log
 -1
 commit 96c2eb46b96bb0cd47e3ae7932d32401a6a28421
 Author: Anssi Kääriäinen <[email protected]>
 Date:   Sat Jun 2 03:40:23 2012 +0300

     Added pre-add_q stage to sql/query.py

 akaariai@akaariai-UX31E:~/Programming/django/django_test/django$ cd ..
 akaariai@akaariai-UX31E:~/Programming/django/django_test$ cat test.py

 from django.core.management import setup_environ
 import settings
 setup_environ(settings)
 from django.db.models import Q, Count
 from django.contrib.auth.models import User
 q1 = Q(username='tim')
 q2 = Q(groups__count__gt=1)
 query = User.objects.annotate(Count('groups'))
 print query.filter(q1 | q2).query

 akaariai@akaariai-UX31E:~/Programming/django/django_test$ python test.py

 SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name",
 "auth_user"."last_name", "auth_user"."email", "auth_user"."password",
 "auth_user"."is_staff", "auth_user"."is_active",
 "auth_user"."is_superuser",
 "auth_user"."last_login", "auth_user"."date_joined",
 COUNT("auth_user_groups"."group_id") AS "groups__count"
 FROM "auth_user"
 LEFT OUTER JOIN "auth_user_groups" ON ("auth_user"."id" =
 "auth_user_groups"."user_id")
 GROUP BY "auth_user"."id", "auth_user"."username",
 "auth_user"."first_name",
 "auth_user"."last_name", "auth_user"."email", "auth_user"."password",
 "auth_user"."is_staff", "auth_user"."is_active",
 "auth_user"."is_superuser",
 "auth_user"."last_login", "auth_user"."date_joined"
 HAVING ("auth_user"."username" = tim  OR
 COUNT("auth_user_groups"."group_id") > 1 )
 }}}
 So, for me this seems to give the correct result.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/11293#comment:24>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to