summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index e2d273994e..d1c4e5446b 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -416,12 +416,12 @@ class Query(object):
# aren't smart enough to remove the existing annotations from the
# query, so those would force us to use GROUP BY.
#
- # If the query has limit or distinct, then those operations must be
- # done in a subquery so that we are aggregating on the limit and/or
- # distinct results instead of applying the distinct and limit after the
- # aggregation.
+ # If the query has limit or distinct, or uses set operations, then
+ # those operations must be done in a subquery so that the query
+ # aggregates on the limit and/or distinct results instead of applying
+ # the distinct and limit after the aggregation.
if (isinstance(self.group_by, list) or has_limit or has_existing_annotations or
- self.distinct):
+ self.distinct or self.combinator):
from django.db.models.sql.subqueries import AggregateQuery
outer_query = AggregateQuery(self.model)
inner_query = self.clone()