Opened 3 weeks ago
Last modified 4 days ago
#37372 assigned Bug
Handling of null values in __in lookups is inconsistent
| Reported by: | Annabelle Wiegart | Owned by: | Annabelle Wiegart |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 6.1 |
| Severity: | Normal | Keywords: | null, in, lookup |
| Cc: | Simon Charette | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When the right-hand side of an __in lookup contains None, several problems are surfaced.
- The resulting querysets differ from the same query being constructed with
Qqueries combined with OR. .filter()and.exclude()produce non-complementary querysets.- Objects with None values are discarded.
This happens when testing against a single table as well when spanning relationships.
The problems are related to the interference between two tickets:
#20024 was created 14 years ago. The suggested change made sense back then, but conflicts with the fix for #31667 implemented in the meantime. This led to the fix for #20024 being ineffective, and the targeting of null values in __in lookups being made impossible.
DryORM fiddle: https://dryorm.xterm.info/in-lookups-with-none
Change History (9)
comment:1 by , 3 weeks ago
| Cc: | added |
|---|---|
| Component: | Uncategorized → Database layer (models, ORM) |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
comment:2 by , 3 weeks ago
| Description: | modified (diff) |
|---|
comment:3 by , 3 weeks ago
| Has patch: | set |
|---|
comment:4 by , 2 weeks ago
| Description: | modified (diff) |
|---|
comment:6 by , 5 days ago
| Patch needs improvement: | set |
|---|
Annabelle's PR will need a rebase after 31c3e4cf7544597600141d9be60bd919371114c9.
comment:7 by , 4 days ago
I rebased PR 22040 on the current main to incorporate 31c3e4cf7544597600141d9be60bd919371114c9.
comment:8 by , 4 days ago
| Patch needs improvement: | unset |
|---|
comment:9 by , 4 days ago
| Patch needs improvement: | set |
|---|
Thanks for the rebase Anna, I was right in the middle of the review so I'll flip it back to needs improvement until the null handling part is ported to build_filter and the eager OUTER JOIN for negated __in=[None] is addressed.
Annabelle and I worked on this project during the Django on the Med 2026 sprint.