From 8f939cf55bc4a4de63c859f033cf5da5378e2d30 Mon Sep 17 00:00:00 2001 From: Jonathan Rohde Date: Mon, 24 Jun 2024 13:45:33 +0200 Subject: [PATCH] feat(sqlalchemy): some fixes --- backend/apps/webui/models/users.py | 1 + backend/main.py | 5 ++--- backend/utils/utils.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/apps/webui/models/users.py b/backend/apps/webui/models/users.py index e1c5ca9f3..9e1e25ac6 100644 --- a/backend/apps/webui/models/users.py +++ b/backend/apps/webui/models/users.py @@ -185,6 +185,7 @@ class UsersTable: Session.query(User).filter_by(id=id).update( {"last_active_at": int(time.time())} ) + Session.commit() user = Session.query(User).filter_by(id=id).first() return UserModel.model_validate(user) diff --git a/backend/main.py b/backend/main.py index 2120b499a..ad519bdcb 100644 --- a/backend/main.py +++ b/backend/main.py @@ -794,11 +794,10 @@ app.add_middleware( ) @app.middleware("http") -async def remove_session_after_request(request: Request, call_next): +async def commit_session_after_request(request: Request, call_next): response = await call_next(request) - log.debug("Removing session after request") + log.debug("Commit session after request") Session.commit() - Session.remove() return response diff --git a/backend/utils/utils.py b/backend/utils/utils.py index 6409fc7aa..fbc539af5 100644 --- a/backend/utils/utils.py +++ b/backend/utils/utils.py @@ -113,8 +113,8 @@ def get_current_user( ) -def get_current_user_by_api_key(db: Session, api_key: str): - user = Users.get_user_by_api_key(db, api_key) +def get_current_user_by_api_key(api_key: str): + user = Users.get_user_by_api_key(api_key) if user is None: raise HTTPException( @@ -122,7 +122,7 @@ def get_current_user_by_api_key(db: Session, api_key: str): detail=ERROR_MESSAGES.INVALID_TOKEN, ) else: - Users.update_user_last_active_by_id(db, user.id) + Users.update_user_last_active_by_id(user.id) return user