fix(gateway): resolve_project 改两步查询避免 JOIN 触发 collation 冲突

This commit is contained in:
ymq 2026-08-17 13:33:28 +08:00
parent 286f0cb4dd
commit bb29d6d634

View File

@ -83,15 +83,18 @@ class Gateway:
db = DBPools()
async with db.sqlorContext("pipeline") as sor:
recs = await sor.sqlExe(
"SELECT s.current_project_id, s.default_llm_id, l.name as llm_name "
"FROM pipeline_agent_settings s "
"LEFT JOIN llm l ON l.id = s.default_llm_id AND l.status='active' "
"WHERE s.user_id=${u}$",
"SELECT current_project_id, default_llm_id FROM pipeline_agent_settings WHERE user_id=${u}$",
{"u": user_id})
if recs:
ctx["pid"] = getattr(recs[0], "current_project_id", "") or ""
ctx["default_llm_id"] = getattr(recs[0], "default_llm_id", "") or ""
ctx["default_llm_name"] = getattr(recs[0], "llm_name", "") or ""
# 单独查 llm.name避免 JOIN 触发两表字段 collation 不一致)
if ctx["default_llm_id"]:
llm_recs = await sor.sqlExe(
"SELECT name FROM llm WHERE id=${id}$ AND status='active'",
{"id": ctx["default_llm_id"]})
if llm_recs:
ctx["default_llm_name"] = getattr(llm_recs[0], "name", "") or ""
if ctx["pid"]:
proj = await sor.sqlExe(
"SELECT name, pipeline_id FROM sd_projects WHERE id=${p}$",