fix: hardcode base_discountid to avoid sqlExe KeyError in DSPY

This commit is contained in:
yumoqing 2026-07-04 19:58:55 +08:00
parent 9645d397b6
commit da88b99ca1

View File

@ -2,7 +2,7 @@
# 参数: discountid (必需) # 参数: discountid (必需)
discountid = params_kw.get('discountid') discountid = params_kw.get('discountid')
debug(f'get_products_with_discount called: params_kw keys={list(params_kw.keys())}, discountid={discountid}') debug(f'get_products_with_discount called: discountid={discountid}')
if not discountid: if not discountid:
return {"total": 0, "rows": []} return {"total": 0, "rows": []}
@ -13,17 +13,9 @@ if not user_orgid:
ns = params_kw.copy() ns = params_kw.copy()
if not ns.get('page'): if not ns.get('page'):
ns['page'] = 1 ns['page'] = 1
ns['org_id'] = user_orgid ns['org_id'] = user_orgid
# 基准折扣方案: 全部用户适用 (customerid='*')
db = DBPools() ns['base_discountid'] = '_HeaX_-9nOg5kEW3qNVCg'
dbname = get_module_dbname('discount')
# 查询基准折扣方案ID (customerid='*', 全部用户适用)
base_sql = "SELECT id FROM discount WHERE customerid='*' AND resellerid=${org_id}$ LIMIT 1"
async with db.sqlorContext(dbname) as sor:
base_recs = await sor.sqlExe(base_sql, ns.copy())
base_discountid = base_recs[0].id if base_recs else discountid
ns['base_discountid'] = base_discountid
sql = ''' sql = '''
SELECT SELECT
@ -46,8 +38,9 @@ WHERE p.org_id = ${org_id}$ AND p.status = '1'
ORDER BY pc.name, p.product_name ORDER BY pc.name, p.product_name
''' '''
debug(f'get_products_with_discount: org_id={user_orgid}, discountid={discountid}, dbname={dbname}, base_discountid={ns["base_discountid"]}') dbname = get_module_dbname('discount')
db = DBPools()
async with db.sqlorContext(dbname) as sor: async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns.copy()) r = await sor.sqlPaging(sql, ns.copy())
debug(f'{ns=},get_products_with_discount: returned {len(r.get("rows", []))} products') debug(f'get_products_with_discount: returned {len(r.get("rows", []))} products')
return r return r