Skip to content

Commit 8d7deb1

Browse files
author
guoyanfeng
committed
- 修复fastapi alchemy中如果默认的连接失败ping操作也会失败的问题
- 更改flask alchemy中如果ping操作默认key的类型值 Signed-off-by: guoyanfeng <guo.yanfeng@dataeveryday.com>
1 parent 2537f4d commit 8d7deb1

6 files changed

Lines changed: 45 additions & 10 deletions

File tree

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
## fessql Changelog
22

3+
###[1.0.4] - 2021-1-14
4+
5+
#### Added
6+
- 经过项目测试可以发布正式版本
7+
8+
#### Changed
9+
- 修复fastapi alchemy中如果默认的连接失败ping操作也会失败的问题
10+
- 更改flask alchemy中如果ping操作默认key的类型值
11+
12+
313
###[1.0.3b1~1.0.3b3] - 2020-12-8
414

515
#### Added

fessql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
"__version__",
2929
)
3030

31-
__version__ = "1.0.3b3"
31+
__version__ = "1.0.4"

fessql/dbalchemy/fastapi_alchemy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .._alchemy import AlchemyMixIn
2727
from .._err_msg import mysql_msg
2828
from ..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

fessql/dbalchemy/flask_alchemy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self) -> None:
4040
from .._cachelru import LRU
4141
from .._err_msg import mysql_msg
4242
from ..err import DBDuplicateKeyError, DBError, FuncArgsError, HttpError
43-
from ..utils import _verify_message
43+
from ..utils import _verify_message, Undefined
4444

4545
__all__ = ("FlaskAlchemy",)
4646

@@ -198,8 +198,8 @@ def ping_session(self, session: Union[Session, scoped_session] = None, reconnect
198198
except sqlalchemy_err.OperationalError as err:
199199
if reconnect:
200200
if isinstance(session, Session):
201-
bind_key = getattr(session, "bind_key", "")
202-
if bind_key:
201+
bind_key = getattr(session, "bind_key", Undefined)
202+
if bind_key != Undefined:
203203
with self.set_bindkey(bind_key):
204204
self.scoped_sessions[bind_key].remove()
205205
session = self.scoped_sessions[bind_key]()

fessql/utils.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"""
99
import weakref
1010
from collections import MutableMapping, MutableSequence
11-
from typing import Dict, List, Union
11+
from typing import Any, Dict, List, TypeVar, Union
1212

13-
__all__ = ("_verify_message", "gen_class_name", "Cached")
13+
__all__ = ("_verify_message", "gen_class_name", "Cached", "Undefined")
1414

1515

1616
def _verify_message(src_message: Dict, message: Union[List, Dict]):
@@ -67,3 +67,27 @@ class Cached(metaclass=_Cached):
6767
6868
"""
6969
pass
70+
71+
72+
T = TypeVar('T')
73+
74+
75+
class UndefinedType(object):
76+
"""
77+
未定义变量类
78+
Args:
79+
Returns:
80+
81+
"""
82+
83+
def __repr__(self) -> str:
84+
return 'VarUndefined'
85+
86+
def __copy__(self: T) -> T:
87+
return self
88+
89+
def __deepcopy__(self: T, _: Any) -> T:
90+
return self
91+
92+
93+
Undefined = UndefinedType()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
keywords="mysql, asyncio, crud, session",
5050
license='MIT',
5151
classifiers=[
52-
'Development Status :: 4 - Beta',
52+
'Development Status :: 5 - Production/Stable',
5353
'Intended Audience :: Developers',
5454
'License :: OSI Approved :: MIT License',
5555
'Natural Language :: Chinese (Simplified)',

0 commit comments

Comments
 (0)