fix(publish): call sync_llm_product outside transaction block (stale read before commit)
This commit is contained in:
parent
0c4bc661eb
commit
89e6d7cb25
@ -12,20 +12,21 @@ try:
|
|||||||
await sor.U('llm', {'id': record_id, 'status': action})
|
await sor.U('llm', {'id': record_id, 'status': action})
|
||||||
result['success'] = True
|
result['success'] = True
|
||||||
result['message'] = '上架成功' if action == 'published' else '下架成功'
|
result['message'] = '上架成功' if action == 'published' else '下架成功'
|
||||||
if action == 'published':
|
if action == 'published':
|
||||||
env = request._run_ns
|
# 同步必须放在事务块外:块内未提交时另一连接读到旧状态
|
||||||
sync_fn = getattr(env, 'sync_llm_product', None)
|
env = request._run_ns
|
||||||
if sync_fn:
|
sync_fn = getattr(env, 'sync_llm_product', None)
|
||||||
try:
|
if sync_fn:
|
||||||
sync_result = await sync_fn(record_id)
|
try:
|
||||||
except Exception as sync_e:
|
sync_result = await sync_fn(record_id)
|
||||||
sync_result = {'success': False, 'error': str(sync_e)}
|
except Exception as sync_e:
|
||||||
if not sync_result:
|
sync_result = {'success': False, 'error': str(sync_e)}
|
||||||
result['message'] += ',已同步为产品'
|
if not sync_result:
|
||||||
elif sync_result.get('success'):
|
result['message'] += ',已同步为产品'
|
||||||
result['message'] += ',已同步为产品'
|
elif sync_result.get('success'):
|
||||||
else:
|
result['message'] += ',已同步为产品'
|
||||||
result['message'] += ',但产品同步失败: ' + str(sync_result.get('error', '未知错误'))
|
else:
|
||||||
|
result['message'] += ',但产品同步失败: ' + str(sync_result.get('error', '未知错误'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result['message'] = str(e)
|
result['message'] = str(e)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user