python
config_error
ai_generated
true
pydantic.errors.ConfigError: default_factory 必须是可调用对象
pydantic.errors.ConfigError: default_factory must be a callable
ID: python/pydantic-field-default-factory-error
80%修复率
87%置信度
0证据数
2024-04-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.x | active | — | — | — |
根因分析
Field 中的 default_factory 参数不是可调用对象(例如列表或整数),导致 ConfigError。
English
The default_factory argument in Field is not a callable (e.g., a list or int), causing ConfigError.
解决方案
-
95% 成功率
Use default_factory=list or lambda: []
-
85% 成功率
Use default=[] instead of default_factory
无效尝试
常见但无效的做法:
-
90% 失败
List is not callable, must be a function like list.
-
60% 失败
Lambda must be callable, but syntax errors possible.