From b33e77702858d33001a42e279fdeea0aab0095ca Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 19 Oct 2023 17:39:15 +0800 Subject: [PATCH] fix bug --- app/db/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/db/__init__.py b/app/db/__init__.py index 3f9a436c..19649177 100644 --- a/app/db/__init__.py +++ b/app/db/__init__.py @@ -1,4 +1,4 @@ -from typing import Tuple +from typing import Tuple, Optional, Generator from sqlalchemy import create_engine, QueuePool from sqlalchemy.orm import sessionmaker, Session, scoped_session @@ -22,7 +22,7 @@ SessionFactory = sessionmaker(bind=Engine) ScopedSession = scoped_session(SessionFactory) -def get_db(): +def get_db() -> Generator: """ 获取数据库会话,用于WEB请求 :return: Session @@ -36,7 +36,7 @@ def get_db(): db.close() -def get_args_db(args: tuple, kwargs: dict): +def get_args_db(args: tuple, kwargs: dict) -> Optional[Session]: """ 从参数中获取数据库Session对象 """ @@ -58,7 +58,7 @@ def update_args_db(args: tuple, kwargs: dict, db: Session) -> Tuple[tuple, dict] """ 更新参数中的数据库Session对象,关键字传参时更新db的值,否则更新第1或第2个参数 """ - if kwargs: + if kwargs and 'db' in kwargs: kwargs['db'] = db elif args: if args[0] is None: