1
0
mirror of https://github.com/django/django.git synced 2025-10-29 16:46:11 +00:00

[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 801a84ae32 from master
This commit is contained in:
Paweł Marczewski
2015-05-24 19:05:56 +02:00
committed by Tim Graham
parent 1ac4c7d415
commit 2aa2b9f291
3 changed files with 10 additions and 0 deletions

View File

@@ -472,6 +472,9 @@ class Query(object):
def has_results(self, using):
q = self.clone()
if not q.distinct:
if q.group_by is True:
q.add_fields((f.attname for f in self.model._meta.concrete_fields), False)
q.set_group_by()
q.clear_select_clause()
q.clear_ordering(True)
q.set_limits(high=1)