#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:  1
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by uwe+django@…):

 * status:  closed => reopened
 * severity:   => Normal
 * type:   => Bug
 * version:  master => 1.4
 * easy:   => 0
 * ui_ux:   => 0
 * resolution:  fixed =>


Comment:

 I think I hit exactly this bug with Django 1.4 (from Debian 1.4-1)

 {{{
 >>> 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'))
 >>> query.filter(q1)
 [<User: tim>]
 >>> query.filter(q2)
 [<User: uwe>]
 >>> query.filter(q1 | q2)
 []
 }}}

 I expected the last result to contain both, tim and uwe.

 {{{
 >>> query.filter(q1 | q2).query.sql_with_params()
 ('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`) WHERE
 (`auth_user`.`username` = %s ) 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
 COUNT(`auth_user_groups`.`group_id`) > %s  ORDER BY NULL', ('tim', 1))
 }}}

 I guess the former 'fixed' marking only applies to the easier case in the
 original report.

 Thanks

-- 
Ticket URL: <https://code.djangoproject.com/ticket/11293#comment:20>
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