summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
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 84e240d1f4..d53b9d1c5d 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -410,7 +410,7 @@ class SQLCompiler:
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 596dc44860..70ea85a275 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -411,12 +411,12 @@ class Query:
# 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, tuple) 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()