Skip to content

Commit

Permalink
Change from_orm by model_validate
Browse files Browse the repository at this point in the history
  • Loading branch information
jonra1993 committed Dec 30, 2023
1 parent 5fbe141 commit 59cd4db
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backend/app/app/api/v1/endpoints/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def export_users_list(
"""
users = await crud.user.get_multi_ordered(limit=1000, order_by="id")
users_list = [
IUserRead.from_orm(user) for user in users
IUserRead.model_validate(user) for user in users
] # Creates a pydantic list of object
users_df = pd.DataFrame([s.__dict__ for s in users_list])
if file_extension == FileExtensionEnum.xls:
Expand Down Expand Up @@ -88,7 +88,7 @@ async def export_heroes_list(
"""
heroes = await crud.hero.get_multi_ordered(limit=1000, order_by="id")
heroes_list = [
IHeroRead.from_orm(hero) for hero in heroes
IHeroRead.model_validate(hero) for hero in heroes
] # Creates a pydantic list of object
heroes_df = pd.DataFrame([s.__dict__ for s in heroes_list])
if file_extension == FileExtensionEnum.xls:
Expand Down
2 changes: 1 addition & 1 deletion backend/app/app/crud/base_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async def create(
db_session: AsyncSession | None = None,
) -> ModelType:
db_session = db_session or self.db.session
db_obj = self.model.from_orm(obj_in) # type: ignore
db_obj = self.model.model_validate(obj_in) # type: ignore

if created_by_id:
db_obj.created_by_id = created_by_id
Expand Down
4 changes: 2 additions & 2 deletions backend/app/app/crud/user_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def create_with_role(
self, *, obj_in: IUserCreate, db_session: AsyncSession | None = None
) -> User:
db_session = db_session or super().get_db().session
db_obj = User.from_orm(obj_in)
db_obj = User.model_validate(obj_in)
db_obj.hashed_password = get_password_hash(obj_in.password)
db_session.add(db_obj)
await db_session.commit()
Expand Down Expand Up @@ -73,7 +73,7 @@ async def update_photo(
) -> User:
db_session = super().get_db().session
user.image = ImageMedia(
media=Media.from_orm(image),
media=Media.model_validate(image),
height=heigth,
width=width,
file_format=file_format,
Expand Down
2 changes: 1 addition & 1 deletion backend/app/app/crud/user_follow_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def follow_a_user_by_target_user_id(
new_user_follow = IUserFollowCreate(
user_id=user.id, target_user_id=target_user.id
)
db_obj = UserFollowModel.from_orm(new_user_follow)
db_obj = UserFollowModel.model_validate(new_user_follow)

reverse_follow = await self.get_follow_by_user_id_and_target_user_id(
user_id=target_user.id, target_user_id=user.id
Expand Down
2 changes: 1 addition & 1 deletion backend/app/app/utils/map_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@


def map_models_schema(schema: SchemaType, models: list[ModelType]):
return [schema.from_orm(model) for model in models]
return [schema.model_validate(model) for model in models]

0 comments on commit 59cd4db

Please sign in to comment.