python
type_error
ai_generated
true
类型错误:'NoneType' 对象不可迭代。
TypeError: 'NoneType' object is not iterable
ID: python/fastapi-query-param-type-conflict
80%修复率
85%置信度
0证据数
2024-06-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
查询参数定义为默认 None,但在未检查的情况下用于迭代。
English
Query parameter defined with default None but used in iteration without checking.
解决方案
-
95% 成功率
Use Optional[List[str]] = Query(None) and then if items: for item in items:
-
90% 成功率
Use list = Query(default_factory=list) to ensure always iterable
无效尝试
常见但无效的做法:
-
60% 失败
May still miss cases where param is empty list.
-
80% 失败
Mutable default arguments are shared across requests, causing bugs.