Agreed, we should raise an error for non-boolean values, e.g.
diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
index 9344979c56..fc4a38c4fe 100644
--- a/django/db/models/lookups.py
+++ b/django/db/models/lookups.py
@@ -463,6 +463,11 @@ class IsNull(BuiltinLookup):
prepare_rhs = False
def as_sql(self, compiler, connection):
+ if not isinstance(self.rhs, bool):
+ raise ValueError(
+ 'The QuerySet value for an isnull lookup must be True or '
+ 'False.'
+ )
sql, params = compiler.compile(self.lhs)
if self.rhs:
return "%s IS NULL" % sql, params
I changed the ticket description.