Open
Description
Description
The current code manually maps SQLAlchemy ORM instances to Pydantic models using .model_dump()
and dict unpacking. This creates redundant boilerplate and tight coupling between data structures.
Pydantic v2 introduces from_attributes=True
(formerly from_orm=True
), enabling Pydantic models to load data directly from SQLAlchemy models via attribute access — reducing manual overhead and improving maintainability.
Proposed Solution
Leverage model_validate(instance)
with from_attributes=True
to automatically generate Pydantic models from SQLAlchemy models.
Suggested Implementation
- Add
model_config = ConfigDict(from_attributes=True)
to the relevant Pydantic models (e.g.:PlayerModel
). - Replace manual conversions like
PlayerModel(**player.__dict__)
withPlayerModel.model_validate(player)
Acceptance Criteria
- All Pydantic models involved in ORM serialization use
from_attributes=True
. - Manual dictionary unpacking
(**obj.__dict__)
is removed in favor ofmodel_validate()
. - Unit and integration tests pass without regressions.
- Behavior remains consistent when serializing responses or performing validation.