diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2012-04-29 13:45:46 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2012-04-29 16:27:25 +0300 |
| commit | 5aa51fa99976ad6133dc6dbb226ecba2c65e6be2 (patch) | |
| tree | 018c26c8e35b782490e658d0dcf6695b1b7ef917 /django/db/models/sql | |
| parent | 9350d1d59c1a4e6a9ac246a808f55da35de0df69 (diff) | |
Simplified QuerySet field.null handling
QuerySet had previously some complex logic for dealing with nullable
fields in negated add_filter() calls. It seems the logic is leftover
from a time where the WhereNode wasn't as intelligent in handling
field__in=[] conditions.
Thanks to aaugustin for comments on the patch.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 780f93e72e..cf527b18b0 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1193,14 +1193,15 @@ class Query(object): entry.negate() self.where.add(entry, AND) break - if not (lookup_type == 'in' - and not hasattr(value, 'as_sql') - and not hasattr(value, '_as_sql') - and not value) and field.null: - # Leaky abstraction artifact: We have to specifically - # exclude the "foo__in=[]" case from this handling, because - # it's short-circuited in the Where class. - # We also need to handle the case where a subquery is provided + if field.null: + # In SQL NULL = anyvalue returns unknown, and NOT unknown + # is still unknown. However, in Python None = anyvalue is False + # (and not False is True...), and we want to return this Python's + # view of None handling. So we need to specifically exclude the + # NULL values, and because we are inside NOT branch they will + # be included in the final resultset. We are essentially creating + # SQL like this here: NOT (col IS NOT NULL), where the first NOT + # is added in upper layers of the code. self.where.add((Constraint(alias, col, None), 'isnull', False), AND) if can_reuse is not None: |
