Skip to content

Commit

Permalink
Handle isnull when value lhs is a value.
Browse files Browse the repository at this point in the history
  • Loading branch information
WaVEV committed Nov 10, 2024
1 parent cef0425 commit 840901a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions django_mongodb/lookups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.core.exceptions import EmptyResultSet, FullResultSet
from django.db import NotSupportedError
from django.db.models.expressions import Value
from django.db.models.fields.related_lookups import In, MultiColSource, RelatedIn
from django.db.models.lookups import (
BuiltinLookup,
Expand Down Expand Up @@ -48,6 +50,14 @@ def in_(self, compiler, connection):
def is_null(self, compiler, connection):
if not isinstance(self.rhs, bool):
raise ValueError("The QuerySet value for an isnull lookup must be True or False.")
if isinstance(self.lhs, Value):
if self.lhs.value is None or (
self.lhs.value == "" and connection.features.interprets_empty_strings_as_nulls
):
result_exception = FullResultSet if self.rhs else EmptyResultSet
else:
result_exception = EmptyResultSet if self.rhs else FullResultSet
raise result_exception
lhs_mql = process_lhs(self, compiler, connection)
return connection.mongo_operators["isnull"](lhs_mql, self.rhs)

Expand Down

0 comments on commit 840901a

Please sign in to comment.