fix: monkey-patch get_business_date to use initialized db, not empty DBPools()
This commit is contained in:
parent
0f25f5d7de
commit
2635d22cc9
@ -30,9 +30,22 @@ from product_management import get_manager
|
|||||||
p = ProgramPath()
|
p = ProgramPath()
|
||||||
config = getConfig(NS={'workdir': os.getcwd(), 'ProgramPath': p})
|
config = getConfig(NS={'workdir': os.getcwd(), 'ProgramPath': p})
|
||||||
db = DBPools(config.databases)
|
db = DBPools(config.databases)
|
||||||
# 防止 businessdate._get_db() 创建新的空 DBPools 实例
|
# 生产环境 get_business_date 内直接 db=DBPools() 创建空实例 → sqlorFactory(None)
|
||||||
|
# 替换为使用已初始化的 db
|
||||||
import appbase.businessdate as _bd
|
import appbase.businessdate as _bd
|
||||||
_bd._get_db = lambda: db
|
_orig_gbd = _bd.get_business_date
|
||||||
|
async def _patched_get_business_date(sor=None):
|
||||||
|
async def _f(sor):
|
||||||
|
sql = "select * from params where params_name = 'business_date'"
|
||||||
|
recs = await sor.sqlExe(sql, {})
|
||||||
|
if len(recs) > 0:
|
||||||
|
return recs[0]['params_value']
|
||||||
|
raise Exception('BusinessDateParamsError')
|
||||||
|
if sor:
|
||||||
|
return await _f(sor)
|
||||||
|
async with db.sqlorContext(get_module_dbname('appbase')) as sor:
|
||||||
|
return await _f(sor)
|
||||||
|
_bd.get_business_date = _patched_get_business_date
|
||||||
|
|
||||||
def get_module_dbname(m):
|
def get_module_dbname(m):
|
||||||
return 'sage'
|
return 'sage'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user