fix(pricing): get_pricing_display 缓存命中崩——get_ppid_pricing 返回 dict 时 r.pricing_data 抛 AttributeError
根因:get_ppid_pricing 走 Redis 缓存命中返回 dict(JSON 反序列化),未命中返回 DictObject(sqlor 行对象)。get_pricing_display 里 r.pricing_data 在 try 块外用 属性访问,缓存命中即抛 AttributeError → 展示价间歇性返回'定价数据为空'。 buffered_charging 早做了 hasattr 兼容,get_pricing_display 漏了同款处理。 修复:hasattr(r,'pricing_data')/isinstance dict/r['pricing_data'] 三路兼容。
This commit is contained in:
parent
b193b402ee
commit
38390ae01f
@ -803,7 +803,15 @@ async def get_pricing_display(ppid, model=None):
|
||||
r = await PricingProgram.get_ppid_pricing(ppid)
|
||||
except Exception:
|
||||
return None
|
||||
pricing_data_str = r.pricing_data
|
||||
# get_ppid_pricing 缓存命中时返回 dict(Redis JSON 反序列化),
|
||||
# 未命中时返回 DictObject(sqlor 行对象),两者都要兼容(同 buffered_charging 的处理,
|
||||
# 2026-09-06 修复:此前缓存命中即抛 AttributeError 致展示价间歇性"定价数据为空")。
|
||||
if hasattr(r, 'pricing_data'):
|
||||
pricing_data_str = r.pricing_data
|
||||
elif isinstance(r, dict):
|
||||
pricing_data_str = r.get('pricing_data')
|
||||
else:
|
||||
pricing_data_str = r['pricing_data']
|
||||
d = yaml.safe_load(pricing_data_str)
|
||||
if not d:
|
||||
raise Exception(f'{ppid} pricing_data 为空')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user