Skip to content

Commit

Permalink
Implement fix for empty aggregate (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
dauinsight authored Dec 22, 2023
1 parent cb8aee0 commit e6748e0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mssql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if django.VERSION >= (3, 1):
from django.db.models.fields.json import compile_json_path, KeyTransform as json_KeyTransform
if django.VERSION >= (4, 2):
from django.core.exceptions import FullResultSet
from django.core.exceptions import EmptyResultSet, FullResultSet

def _as_sql_agv(self, compiler, connection):
return self.as_sql(compiler, connection, template='%(function)s(CONVERT(float, %(field)s))')
Expand Down Expand Up @@ -241,6 +241,11 @@ def as_sql(self, with_limits=True, with_col_aliases=False):
if django.VERSION >= (4, 2):
try:
where, w_params = self.compile(self.where) if self.where is not None else ("", [])
except EmptyResultSet:
if self.elide_empty:
raise
# Use a predicate that's always False.
where, w_params = "0 = 1", []
except FullResultSet:
where, w_params = "", []
try:
Expand Down

0 comments on commit e6748e0

Please sign in to comment.