Skip to content

Commit e6748e0

Browse files
authored
Implement fix for empty aggregate (#324)
1 parent cb8aee0 commit e6748e0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mssql/compiler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
if django.VERSION >= (3, 1):
1717
from django.db.models.fields.json import compile_json_path, KeyTransform as json_KeyTransform
1818
if django.VERSION >= (4, 2):
19-
from django.core.exceptions import FullResultSet
19+
from django.core.exceptions import EmptyResultSet, FullResultSet
2020

2121
def _as_sql_agv(self, compiler, connection):
2222
return self.as_sql(compiler, connection, template='%(function)s(CONVERT(float, %(field)s))')
@@ -241,6 +241,11 @@ def as_sql(self, with_limits=True, with_col_aliases=False):
241241
if django.VERSION >= (4, 2):
242242
try:
243243
where, w_params = self.compile(self.where) if self.where is not None else ("", [])
244+
except EmptyResultSet:
245+
if self.elide_empty:
246+
raise
247+
# Use a predicate that's always False.
248+
where, w_params = "0 = 1", []
244249
except FullResultSet:
245250
where, w_params = "", []
246251
try:

0 commit comments

Comments
 (0)