Skip to content

Commit b5792cd

Browse files
authored
Update db_op.py
1 parent 23aa724 commit b5792cd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

app/database/async/db_op.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ async def add_user(
2020
"""
2121
add new user
2222
"""
23-
db_user = UserModel(username, password)
2423
async with self.get_async_session() as session:
25-
async with session.begin():
26-
try:
24+
try:
25+
async with session.begin():
26+
db_user = UserModel(username, password)
2727
session.add(db_user)
2828
await session.flush() # refresh own primary key
2929
session.expunge(db_user) # release data
3030
# begin() context will auto commit trancastion
31-
except SQLAlchemyError as sql_ex:
32-
raise sql_ex
33-
return db_user
31+
return db_user
32+
except SQLAlchemyError as sql_ex:
33+
raise sql_ex
34+

0 commit comments

Comments
 (0)