python
config_error
ai_generated
true
PydanticUserError: `orm_mode` is removed. Use `from_attributes=True` instead.
ID: python/fastapi-pydantic-config-orm-mode
80%Fix Rate
89%Confidence
0Evidence
2024-05-09First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
A Pydantic model still uses v1's `orm_mode = True` Config under v2.
generic中文
Pydantic 模型在 v2 下仍使用 v1 的 `orm_mode = True` 配置。
Workarounds
-
93% success
Use v2 config: class UserOut(BaseModel): model_config = ConfigDict(from_attributes=True) -
85% success
Validate manually with model_validate(obj, from_attributes=True).
Dead Ends
Common approaches that don't work:
-
90% fail
orm_mode is rejected outright, so the model fails to import.
-
70% fail
Then ORM objects can't be validated from attributes, breaking response_model.