fix(buffered_charging): 兼容 get_ppid_pricing 缓存返回的 dict
get_ppid_pricing 第一次返回 DictObject(sqlor 行对象),经 cache_set 序列化到 Redis 后, 缓存命中时 cache_get 返回 dict(JSON 反序列化)。buffered_charging 原用 r.pricing_data 属性访问,缓存命中时崩 'dict' object has no attribute 'pricing_data'。 影响:任何走 buffered_charging 的计费(calculate_product_cost 等)第二次调用必崩。 改为兼容 hasattr/dict/下标三种访问。
This commit is contained in:
parent
354e2aabf7
commit
b193b402ee
@ -461,8 +461,15 @@ class PricingProgram:
|
|||||||
|
|
||||||
async def buffered_charging(ppid, data):
|
async def buffered_charging(ppid, data):
|
||||||
r = await PricingProgram.get_ppid_pricing(ppid)
|
r = await PricingProgram.get_ppid_pricing(ppid)
|
||||||
prices = PricingProgram.get_pricing_from_ymalstr(data,
|
# get_ppid_pricing 缓存命中时返回 dict(Redis JSON 反序列化),
|
||||||
r.pricing_data)
|
# 未命中时返回 DictObject(sqlor 行对象),两者都要兼容。
|
||||||
|
if hasattr(r, 'pricing_data'):
|
||||||
|
pricing_data = r.pricing_data
|
||||||
|
elif isinstance(r, dict):
|
||||||
|
pricing_data = r.get('pricing_data')
|
||||||
|
else:
|
||||||
|
pricing_data = r['pricing_data']
|
||||||
|
prices = PricingProgram.get_pricing_from_ymalstr(data, pricing_data)
|
||||||
amt = 0.0
|
amt = 0.0
|
||||||
for p in prices:
|
for p in prices:
|
||||||
p.cost = p.amount # discount removed
|
p.cost = p.amount # discount removed
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user