Skip to content

Commit 113df00

Browse files
committed
Handle isnull when value lhs is a value.
1 parent f981f26 commit 113df00

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

django_mongodb/lookups.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from django.core.exceptions import EmptyResultSet, FullResultSet
12
from django.db import NotSupportedError
3+
from django.db.models.expressions import Value
24
from django.db.models.fields.related_lookups import In, MultiColSource, RelatedIn
35
from django.db.models.lookups import (
46
BuiltinLookup,
@@ -48,6 +50,14 @@ def in_(self, compiler, connection):
4850
def is_null(self, compiler, connection):
4951
if not isinstance(self.rhs, bool):
5052
raise ValueError("The QuerySet value for an isnull lookup must be True or False.")
53+
if isinstance(self.lhs, Value):
54+
if self.lhs.value is None or (
55+
self.lhs.value == "" and connection.features.interprets_empty_strings_as_nulls
56+
):
57+
result_exception = FullResultSet if self.rhs else EmptyResultSet
58+
else:
59+
result_exception = EmptyResultSet if self.rhs else FullResultSet
60+
raise result_exception
5161
lhs_mql = process_lhs(self, compiler, connection)
5262
return connection.mongo_operators["isnull"](lhs_mql, self.rhs)
5363

0 commit comments

Comments
 (0)