== Testcase (see below for setup) ==
Assume at least 2 Users exist in the database.
{{{
>>> User.objects.annotate(c=models.Count('id')).values_list('c')
[(1,), (1,)]
>>> User.objects.annotate(c=models.Count('id')).filter(c__gt=1)
[]
}}}
So far this is to be expected. No user has more than one id--which makes
the following surprising.
{{{
>>> User.objects.annotate(c=models.Count('id')).filter(c__gt=1).exists()
True
}}}
What further raises the suspicion of unintended behavior is that if you
increase the "1" to the number of Users (or higher), then the exists()
starts to return False.
{{{
>>>
User.objects.annotate(c=models.Count('id')).filter(c__gt=User.objects.count()).exists()
False
}}}
== Setup ==
{{{
$ django-admin2 startproject blah
$ cd blah
$ ./manage.py syncdb
...
You have installed Django's auth system, and don't have any superusers
defined.
Would you like to create one now? (yes/no): no
$ ./manage.py shell
>>> from django.contrib.auth.models import User
>>> User.objects.create(username='a')
>>> User.objects.create(username='b')
>>> from django.db import models
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24835>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* severity: Normal => Release blocker
* needs_tests: => 0
* needs_docs: => 0
Comment:
Bisected regression to 0c7633178fa9410f102e4708cef979b873bccb76. Test for
Django's test suite attached.
--
Ticket URL: <https://code.djangoproject.com/ticket/24835#comment:1>
* Attachment "24835-test.diff" added.
* cc: josh.smeaton@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/24835#comment:2>
* owner: nobody => pwmarcz
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/24835#comment:3>
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/4706
--
Ticket URL: <https://code.djangoproject.com/ticket/24835#comment:4>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/24835#comment:5>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/24835#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"801a84ae329a24d9adf01b700429fe8f1285b2b8" 801a84ae]:
{{{
#!CommitTicketReference repository=""
revision="801a84ae329a24d9adf01b700429fe8f1285b2b8"
Fixed #24835 -- Fixed QuerySet.exists() after an annotation with Count()
QuerySet.exists() incorrectly handled query.group_by = True
case (grouping by all select fields), causing GROUP BY
expressions to be wiped along with select fields.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24835#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"2aa2b9f291e43bffc07c535dc5906094e6df0bb7" 2aa2b9f]:
{{{
#!CommitTicketReference repository=""
revision="2aa2b9f291e43bffc07c535dc5906094e6df0bb7"
[1.8.x] Fixed #24835 -- Fixed QuerySet.exists() after an annotation with
Count()
QuerySet.exists() incorrectly handled query.group_by = True
case (grouping by all select fields), causing GROUP BY
expressions to be wiped along with select fields.
Backport of 801a84ae329a24d9adf01b700429fe8f1285b2b8 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24835#comment:8>