fix: create_project iteration_name + _save_ctx race condition

This commit is contained in:
ymq 2026-08-09 22:49:00 +08:00
parent 13f9b3d56f
commit d86307e5f4

View File

@ -98,11 +98,17 @@ async def _load_ctx(sor, uid):
return ctx
async def _save_ctx(sor, uid, pid):
ex = await sor.sqlExe("SELECT id FROM pipeline_agent_settings WHERE user_id=${u}$",{"u":uid})
if ex:
try:
await sor.sqlExe("UPDATE pipeline_agent_settings SET current_project_id=${p}$ WHERE user_id=${u}$",{"p":pid or '','u':uid})
else:
await sor.C('pipeline_agent_settings',{'id':getID(),'user_id':uid,'default_llm_id':'','current_project_id':pid or '','current_iteration_id':''})
ex = await sor.sqlExe("SELECT id FROM pipeline_agent_settings WHERE user_id=${u}$",{"u":uid})
if not ex:
await sor.C('pipeline_agent_settings',{'id':getID(),'user_id':uid,'default_llm_id':'','current_project_id':pid or '','current_iteration_id':''})
except:
# Duplicate key race — update instead
try:
await sor.sqlExe("UPDATE pipeline_agent_settings SET current_project_id=${p}$ WHERE user_id=${u}$",{"p":pid or '','u':uid})
except:
pass
async def _sel_model(sor, pref):
if pref:
@ -153,7 +159,7 @@ async def _exec_tool(sor, tool, params, ctx, uid, org_id):
wid = getID()
ws = f'/d/pipeline/workspaces/{org_id}/{name}'
await sor.C('sd_projects',{'id':pid,'name':name,'description':p.get('description',''),'workspace_dir':ws,'org_id':org_id,'created_by':uid})
await sor.C('sd_iterations',{'id':wid,'project_id':pid,'name':'默认迭代','org_id':org_id})
await sor.C('sd_iterations',{'id':wid,'project_id':pid,'iteration_name':'默认迭代','iteration_type':'default','status':'active','priority':1,'org_id':org_id})
await _save_ctx(sor, uid, pid)
ctx['pid'] = pid; ctx['pname'] = name; ctx['ws'] = ws
return f'OK: 已创建并切换到「{name}」'