summaryrefslogtreecommitdiff
path: root/django/db/models/sql/compiler.py
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2021-09-29 00:00:50 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-09-29 20:23:29 +0200
commitdd1fa3a31b4680c0d3712e6ae122b878138580c7 (patch)
tree10205352e74cd3708581c7c262d25840be6aa12a /django/db/models/sql/compiler.py
parentad36a198a12df4dff65992191b3eb0a474e2daac (diff)
Fixed #33018 -- Fixed annotations with empty queryset.
Thanks Simon Charette for the review and implementation idea.
Diffstat (limited to 'django/db/models/sql/compiler.py')
-rw-r--r--django/db/models/sql/compiler.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 97288c83d7..d1009847e7 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -266,8 +266,12 @@ class SQLCompiler:
try:
sql, params = self.compile(col)
except EmptyResultSet:
- # Select a predicate that's always False.
- sql, params = '0', ()
+ empty_result_set_value = getattr(col, 'empty_result_set_value', NotImplemented)
+ if empty_result_set_value is NotImplemented:
+ # Select a predicate that's always False.
+ sql, params = '0', ()
+ else:
+ sql, params = self.compile(Value(empty_result_set_value))
else:
sql, params = col.select_format(self, sql, params)
ret.append((col, (sql, params), alias))