python
config_error
ai_generated
true
pydantic.errors.ConfigError: default_factory must be a callable
ID: python/pydantic-field-default-factory-error
80%Fix Rate
87%Confidence
0Evidence
2024-04-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
Root Cause
The default_factory argument in Field is not a callable (e.g., a list or int), causing ConfigError.
generic中文
Field 中的 default_factory 参数不是可调用对象(例如列表或整数),导致 ConfigError。
Workarounds
-
95% success
Use default_factory=list or lambda: []
-
85% success
Use default=[] instead of default_factory
Dead Ends
Common approaches that don't work:
-
90% fail
List is not callable, must be a function like list.
-
60% fail
Lambda must be callable, but syntax errors possible.