﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36290	Unnecessary query performed when prefetching nullable foreign key relationships	Simon Charette	Simon Charette	"[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."	Bug	closed	Database layer (models, ORM)	5.2	Release blocker	fixed	prefetch_related foreign object key null	Baptiste Mispelon	Ready for checkin	1	0	0	0	0	0
