diff options
| author | Paweł Marczewski <pwmarcz@gmail.com> | 2015-05-24 19:05:56 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-05-25 20:47:28 -0400 |
| commit | 2aa2b9f291e43bffc07c535dc5906094e6df0bb7 (patch) | |
| tree | 8849922dd789b15006aca84ea05a22393a290e5f /django/db/models/sql/query.py | |
| parent | 1ac4c7d415750ddc648cbf888bc2fbcde933f799 (diff) | |
[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
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 6f883031ef..1a86266e6c 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -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) |
