diff options
| author | Florian Apolloner <florian@apolloner.eu> | 2017-07-14 18:11:29 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-07-15 09:10:42 -0400 |
| commit | 9350f77c69a5cef3d7a9b8078ab33ff43335a112 (patch) | |
| tree | dfcf9ce4877d8d2f2a0d81fb398423e9bb2b780e /django/db/models/sql/query.py | |
| parent | d9ef8ffb5854c9a5fd81f18b3e383accafd6d7ff (diff) | |
[1.11.x] Fixed #28399 -- Fixed QuerySet.count() for union(), difference(), and intersection() queries.
Backport of adab280cefb15659c39558ac26ea392b0a1e456c from master
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 10 |
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() |
