python config_error ai_generated true

pydantic.errors.PydanticUserError: `orm_mode` is deprecated. Use `from_attributes` instead.

ID: python/fastapi-pydantic-v1-v2-migration-error

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2025-10-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2.x active — — —

Root Cause

Code written for Pydantic v1 (`class Config: orm_mode = True`) runs under Pydantic v2, which renamed the setting.

generic

中文

为 Pydantic v1 编写的代码(`class Config: orm_mode = True`)在 Pydantic v2 下运行,而 v2 重命名了该设置。

Workarounds

  1. 95% success
    class UserOut(BaseModel):
        model_config = ConfigDict(from_attributes=True)
        id: int
        name: str
  2. 85% success
    Run `bump-pydantic` codemod: `pip install bump-pydantic && bump-pydantic .` to auto-migrate.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    FastAPI 0.100+ requires Pydantic v2; pip resolver errors.

  2. 85% fail

    Config is ignored; from_orm/validation fails at runtime.