2626from .._alchemy import AlchemyMixIn
2727from .._err_msg import mysql_msg
2828from ..err import DBDuplicateKeyError , DBError , FuncArgsError , HttpError
29+ from ..utils import Undefined
2930
3031__all__ = ("FesPagination" , "FesQuery" , "FesSession" , "FastapiAlchemy" )
3132
@@ -691,8 +692,8 @@ def ping_session(self, session: FesSession, reconnect=True) -> FesSession:
691692 session .execute (text ("SELECT 1" )).first ()
692693 except sqlalchemy_err .OperationalError as err :
693694 if reconnect :
694- bind_key = getattr (session , "bind_key" , "" )
695- if bind_key :
695+ bind_key = getattr (session , "bind_key" , Undefined )
696+ if bind_key != Undefined :
696697 self .sessionmaker_pool [bind_key ].remove ()
697698 session = self .gen_sessionmaker (bind_key )()
698699 session .bind_key = bind_key # 设置bind key
@@ -704,7 +705,7 @@ def ping_session(self, session: FesSession, reconnect=True) -> FesSession:
704705 return session
705706
706707 @contextmanager
707- def gen_session (self , bind_key : str = None ) -> Generator [FesSession , None , None ]:
708+ def gen_session (self , bind_key : Optional [ str ] = None ) -> Generator [FesSession , None , None ]:
708709 """
709710 创建或者获取指定的session
710711
0 commit comments