Changes between Initial Version and Version 8 of Ticket #30841


Ignore:
Timestamp:
Oct 7, 2019, 3:13:28 AM (5 years ago)
Author:
Mariusz Felisiak
Comment:

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.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30841

    • Property Owner changed from nobody to André Ericson
    • Property Triage Stage UnreviewedAccepted
    • Property Summary Using isnull to a non-boolean value does not promote joinPrevent using __isnull lookup with non-boolean value.
    • Property Type BugCleanup/optimization
  • Ticket #30841 – Description

    initial v8  
    1 Using `isnull` filter with a non-boolean value will not promote `INNER JOIN` to an `OUTER JOIN` leading to inconsistent behaviour.
    2 
    3 I'm submitting a PR together with this ticket and will link it here.
     1`__isnull` should not allow for non-boolean values. Using truthy/falsey doesn't promote `INNER JOIN` to an `OUTER JOIN` but works fine for a simple queries. Using non-boolean values is [https://docs.djangoproject.com/en/2.2/ref/models/querysets/#isnull undocumented] and untested. IMO we should raise an error for non-boolean values to avoid confusion and for consistency.
Back to Top