fix: _find_project fuzzy match in Python (avoid aiomysql % format issue)

This commit is contained in:
ymq 2026-08-08 14:56:02 +08:00
parent 168b5aaa88
commit 588e5be5d6

View File

@ -447,12 +447,16 @@ async def _find_project(sor, name, org_id):
{"name": name, "oid": org_id})
if recs:
return recs[0]
# Fuzzy match: name contains keyword
# Use f-string for LIKE to avoid aiomysql % escaping issues
kw = name.replace("'", "''")
sql = f"SELECT id, name FROM sd_projects WHERE name LIKE '%{kw}%' AND org_id='{org_id}' LIMIT 1"
recs = await sor.sqlExe(sql, {})
return recs[0] if recs else None
# Fuzzy: load all projects for this org and match in Python
all_recs = await sor.sqlExe(
"SELECT id, name FROM sd_projects WHERE org_id=${oid}$",
{"oid": org_id})
kw = name.lower()
for rec in (all_recs or []):
rname = (getattr(rec, 'name', '') or '').lower()
if kw in rname:
return rec
return None
# ==================== 问题路由 ====================