python
type_error
ai_generated
true
TypeError: 'NoneType' object is not iterable
ID: python/fastapi-query-param-type-conflict
80%Fix Rate
85%Confidence
0Evidence
2024-06-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Query parameter defined with default None but used in iteration without checking.
generic中文
查询参数定义为默认 None,但在未检查的情况下用于迭代。
Workarounds
-
95% success
Use Optional[List[str]] = Query(None) and then if items: for item in items:
-
90% success
Use list = Query(default_factory=list) to ensure always iterable
Dead Ends
Common approaches that don't work:
-
60% fail
May still miss cases where param is empty list.
-
80% fail
Mutable default arguments are shared across requests, causing bugs.