python
config_error
ai_generated
true
pydantic.errors.PydanticUserError: `orm_mode` 已弃用,请使用 `from_attributes`。
pydantic.errors.PydanticUserError: `orm_mode` is deprecated. Use `from_attributes` instead.
ID: python/fastapi-pydantic-v1-v2-migration-error
80%修复率
88%置信度
0证据数
2025-10-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.x | active | — | — | — |
根因分析
为 Pydantic v1 编写的代码(`class Config: orm_mode = True`)在 Pydantic v2 下运行,而 v2 重命名了该设置。
English
Code written for Pydantic v1 (`class Config: orm_mode = True`) runs under Pydantic v2, which renamed the setting.
解决方案
-
95% 成功率
class UserOut(BaseModel): model_config = ConfigDict(from_attributes=True) id: int name: str -
85% 成功率
Run `bump-pydantic` codemod: `pip install bump-pydantic && bump-pydantic .` to auto-migrate.
无效尝试
常见但无效的做法:
-
90% 失败
FastAPI 0.100+ requires Pydantic v2; pip resolver errors.
-
85% 失败
Config is ignored; from_orm/validation fails at runtime.