mirror of
https://github.com/django/django.git
synced 2025-08-22 19:44:44 +00:00
Fixed #33018 -- Fixed annotations with empty queryset.
Thanks Simon Charette for the review and implementation idea.
This commit is contained in:
parent
ad36a198a1
commit
dd1fa3a31b
5 changed files with 33 additions and 4 deletions
|
@ -702,7 +702,13 @@ class Func(SQLiteNumericMixin, Expression):
|
|||
sql_parts = []
|
||||
params = []
|
||||
for arg in self.source_expressions:
|
||||
arg_sql, arg_params = compiler.compile(arg)
|
||||
try:
|
||||
arg_sql, arg_params = compiler.compile(arg)
|
||||
except EmptyResultSet:
|
||||
empty_result_set_value = getattr(arg, 'empty_result_set_value', NotImplemented)
|
||||
if empty_result_set_value is NotImplemented:
|
||||
raise
|
||||
arg_sql, arg_params = compiler.compile(Value(empty_result_set_value))
|
||||
sql_parts.append(arg_sql)
|
||||
params.extend(arg_params)
|
||||
data = {**self.extra, **extra_context}
|
||||
|
@ -1114,6 +1120,7 @@ class Subquery(BaseExpression, Combinable):
|
|||
"""
|
||||
template = '(%(subquery)s)'
|
||||
contains_aggregate = False
|
||||
empty_result_set_value = None
|
||||
|
||||
def __init__(self, queryset, output_field=None, **extra):
|
||||
# Allow the usage of both QuerySet and sql.Query objects.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue