Skip to content

Commit

Permalink
fix(#164): added mapper column key on to_dict func (#165)
Browse files Browse the repository at this point in the history
* fix(#164): added mapper column key on to_dict func

* chore: added noqa

---------

Co-authored-by: Cody Fincher <204685+cofin@users.noreply.github.com>
  • Loading branch information
ysnbyzli and cofin committed May 3, 2024
1 parent 92c1fc5 commit c09f717
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion advanced_alchemy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ def to_dict(self, exclude: set[str] | None = None) -> dict[str, Any]:
dict[str, Any]: A dict representation of the model
"""
exclude = {"sa_orm_sentinel", "_sentinel"}.union(self._sa_instance_state.unloaded).union(exclude or []) # type: ignore[attr-defined]
return {field.name: getattr(self, field.name) for field in self.__table__.columns if field.name not in exclude}
return {
field: getattr(self, field)
for field in self.__mapper__.columns.keys() # noqa: SIM118
if field not in exclude
}


@declarative_mixin
Expand Down

0 comments on commit c09f717

Please sign in to comment.