summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2021-05-21 21:48:46 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-07-02 06:40:54 +0200
commitf3112fde981052801e0c2121027424496c03efdf (patch)
tree6fa1fe3a6a2efc9927df938f60a7a97a74d0737b /django/db/models/sql/query.py
parentfde6fb28984a76d5bee794f4c0458eb25fe56fcd (diff)
Fixed #26430 -- Fixed coalesced aggregation of empty result sets.
Disable the EmptyResultSet optimization when performing aggregation as it might interfere with coalescence.
Diffstat (limited to 'django/db/models/sql/query.py')
-rw-r--r--django/db/models/sql/query.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 814271a1f6..fabb346418 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -273,12 +273,12 @@ class Query(BaseExpression):
memo[id(self)] = result
return result
- def get_compiler(self, using=None, connection=None):
+ def get_compiler(self, using=None, connection=None, elide_empty=True):
if using is None and connection is None:
raise ValueError("Need either using or connection")
if using:
connection = connections[using]
- return connection.ops.compiler(self.compiler)(self, connection, using)
+ return connection.ops.compiler(self.compiler)(self, connection, using, elide_empty)
def get_meta(self):
"""
@@ -494,10 +494,8 @@ class Query(BaseExpression):
outer_query.clear_limits()
outer_query.select_for_update = False
outer_query.select_related = False
- compiler = outer_query.get_compiler(using)
+ compiler = outer_query.get_compiler(using, elide_empty=False)
result = compiler.execute_sql(SINGLE)
- if result is None:
- result = [None] * len(outer_query.annotation_select)
converters = compiler.get_converters(outer_query.annotation_select.values())
result = next(compiler.apply_converters((result,), converters))