#20024: QuerySet.exclude() does not work with lists containing a 'None' element.
-------------------------------------+-------------------------------------
Reporter: stillwater.ke@… | Owner: Jason
| Hall
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jason Hall):
* owner: (none) => Jason Hall
* status: new => assigned
Old description:
> For example:
> {{{
> Entry.objects.exclude(foo__in=[None, 1])
> }}}
> It is supposed to return all items whose foo field is not None or 1, but
> it actually returns an empty query set.
New description:
For example:
{{{
Entry.objects.exclude(foo__in=[None, 1])
}}}
It is supposed to return all items whose foo field is not None or 1, but
it actually returns an empty query set.
--
Comment:
I’ve been reading up on SQL’s tri-valued logic (TRUE / FALSE / UNKNOWN),
which explains why SQL needs IS NULL and IS NOT NULL for comparisons
involving NULL. I knew that when writing queries involving blank values
one is supposed to use IS NULL, now I understand why. Neat.
As of ticket #31667, filter(field__in=[None]) now silently ignores None,
which means some of the earlier concerns about fixing this no longer
apply.
I believe this can be resolved cleanly by checking if None is present in
the rhs, and if so, splitting the clause into an IN condition and an IS
NULL condition joined by OR. That should align exclude(field__in=[None,
X]) with user expectations and prevent SQL NULL logic from leaking into
the ORM unnecessarily.
Assigning to myself and will begin a patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/20024#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070198625f15ba-01287fa7-d248-4851-9f0f-40f2bf8accb9-000000%40eu-central-1.amazonses.com.