summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2017-07-14 18:11:29 +0200
committerTim Graham <timograham@gmail.com>2017-07-15 09:10:42 -0400
commit9350f77c69a5cef3d7a9b8078ab33ff43335a112 (patch)
treedfcf9ce4877d8d2f2a0d81fb398423e9bb2b780e /django/db/models/sql
parentd9ef8ffb5854c9a5fd81f18b3e383accafd6d7ff (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')
-rw-r--r--django/db/models/sql/compiler.py2
-rw-r--r--django/db/models/sql/query.py10
2 files changed, 6 insertions, 6 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index e96cbee71f..6ec2284a91 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -398,7 +398,7 @@ class SQLCompiler(object):
continue
raise
if not parts:
- return [], []
+ raise EmptyResultSet
combinator_sql = self.connection.ops.set_operators[combinator]
if all and combinator == 'union':
combinator_sql += ' ALL'
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()