﻿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
37384	"Iterating F(""pk"") can hang"	Jacob Walls	Django Sprints	"#35603 solved one of the two scenarios that could lead to an infinite hang when `F()` expressions fall back to ""old-style"" iteration protocols via `__getitem__()`. It solved it for **containment** checks by throwing from `__contains__`. It didn't solve it for **iteration**, so we encountered an infinite hang in #37291.

When reviewing the fix for #37291, I began to suggest addressing the root cause by throwing an error from `F.__iter__()` until I realized that it would change the return value of `hasattr(expr, ""__iter__"")`. We have several uses in core like that.

What we should do, I think, is set `F.__iter__ = None`, and then update core (and add release notes) that code should update from:
{{{#!py
if hasattr(expr, ""__iter__""):
}}}
to:
{{{#!py
if getattr(expr, ""__iter__"", None):
}}}

...so that the pythonic way of declaring no-iteration can be read statically.
"	Bug	assigned	Database layer (models, ORM)	5.2	Normal			Simon Charette	Unreviewed	0	0	0	0	0	0
