#37140: NULL handling of exclude() with __in varies between nullable expressions
versus literal None
-------------------------------------+-------------------------------------
Reporter: Sebastian Vera | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: exclude in subquery | Triage Stage:
NULL NOT IN | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Replacing `__in` to perform `EXISTS` query is likely never going to happen
for the reasons discussed in the thread so we'd likely need to introduce
an `__exists` lookup instead to avoid breaking backward compatibility so
knowing that I wouldn't be opposed to documenting this pitfall even if I
suspect folks would only stumble upon the edge case after the fact.
As for ''what'' should be documented as a workaround having the subquery
explicitly exclude `NULL` (e.g. `filter(inner_field__isnull=False)`) is
likely going to be closer to what the ORM would normally generate and I
would avoid tying the problem to `exclude` as the same behaviour exists
for `filter` as well as demonstrated in [https://dbfiddle.uk/i1Kd1GDe this
fiddle].
As alluded to ticket:20024#comment:14 fixing this for all nullable
expressions is quite hard to do the right way. Even if we reduced the
problem to only queryset like right-hand-side we'd still have to find the
column being matched against and alter the query to do the equivalent of
`filter(inner_field__isnull=False)` without causing side effects (e.g.
what if the field is an aggregation or window function?).
--
Ticket URL: <https://code.djangoproject.com/ticket/37140#comment:3>
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/0107019ec72885a5-0ade914b-ae62-4d44-9117-989026df59c8-000000%40eu-central-1.amazonses.com.