File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 44from fastapi import HTTPException , status
55from sqlalchemy .exc import SQLAlchemyError , IntegrityError
66from sqlalchemy .ext .asyncio import AsyncSession
7- from sqlalchemy .ext . declarative import as_declarative , declared_attr
7+ from sqlalchemy .orm import as_declarative , declared_attr
88
99
1010@as_declarative ()
@@ -53,16 +53,19 @@ async def delete(self, db_session: AsyncSession):
5353 except SQLAlchemyError as ex :
5454 raise HTTPException (status_code = status .HTTP_422_UNPROCESSABLE_ENTITY , detail = repr (ex )) from ex
5555
56- async def update (self , db_session : AsyncSession , ** kwargs ):
56+ async def update (self , db : AsyncSession , ** kwargs ):
5757 """
5858
59- :param db_session :
60- :param kwargs:
59+ :param db :
60+ :param kwargs
6161 :return:
6262 """
63- for k , v in kwargs .items ():
64- setattr (self , k , v )
65- await self .save (db_session )
63+ try :
64+ for k , v in kwargs .items ():
65+ setattr (self , k , v )
66+ return await db .commit ()
67+ except SQLAlchemyError as ex :
68+ raise HTTPException (status_code = status .HTTP_422_UNPROCESSABLE_ENTITY , detail = repr (ex )) from ex
6669
6770 async def save_or_update (self , db : AsyncSession ):
6871 try :
You can’t perform that action at this time.
0 commit comments