python
config_error
ai_generated
true
AttributeError: type object 'User' has no attribute 'Config'. Did you mean: 'model_config'?
ID: python/pydantic-model-config-attribute-error
80%Fix Rate
89%Confidence
0Evidence
2024-02-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
Root Cause
Pydantic v1 code using an inner class Config was copied into a v2 project. In v2 the configuration is set via the model_config class attribute with ConfigDict.
generic中文
将 Pydantic v1 中使用内部 class Config 的代码复制到了 v2 项目中。v2 中配置通过 model_config 类属性和 ConfigDict 设置。
Workarounds
-
95% success
from pydantic import BaseModel, ConfigDict class User(BaseModel): model_config = ConfigDict(extra='forbid', frozen=True) name: str -
85% success
pip install bump-pydantic bump-pydantic ./src
Dead Ends
Common approaches that don't work:
-
80% fail
Pydantic v2 ignores the inner Config class entirely; settings silently have no effect and behavior diverges.
-
65% fail
Breaks other v2-only dependencies and pydantic-core bindings; causes cascading import errors across the project.