#36290: Unnecessary query performed when prefetching nullable foreign key
relationships
-------------------------------------+-------------------------------------
Reporter: Simon | Owner: Simon Charette
Charette |
Type: Bug | Status: assigned
Component: Database | Version: 5.2
layer (models, ORM) |
Severity: Release | Keywords: prefetch_related
blocker | foreign object key null
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
[
https://discord.com/channels/856567261900832808/859997770274045954/1357036282651345006
As reported by Baptiste on Discord]
---
Because the `tuple_lookups.TupleIn.process_rhs` logic doesn't replicate
the `None` eliding logic on `lookups.In.process_rhs`
[
https://github.com/django/django/blob/c7ff347c641f2f97fa9f2f7d182982f789a211b4/django/db/models/lookups.py#L527-L536
logic] the usage of `TupleIn` introduced in
626d77e52a3f247358514bcf51c761283968099c to resolve #36116 resulted in the
unnecessary execution of queries of the form
{{{#sql
SELECT "releases_release"."version" FROM "releases_release" WHERE
("releases_release"."version") IN ((NULL))
}}}
which are never going to match because `NULL != NULL` in SQL.
This has to relation to #31667 which introduced this optimization for the
same prefetch related optimization purposes.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36290>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.