From 8e0bbdbbd1ad65dd44744d2d46fcb8376d450dee Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 10 Sep 2026 17:07:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20sqlor=E5=8D=A0=E4=BD=8D=E7=AC=A6?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E9=94=99=E2=80=94=E2=80=94=E8=A7=92=E8=89=B2?= =?UTF-8?q?IN=E5=AD=90=E5=8F=A5=E7=94=A8=E5=AD=97=E9=9D=A2=E9=87=8F?= =?UTF-8?q?=E9=9D=9E=E5=8F=82=E6=95=B0=E5=8D=A0=E4=BD=8D=E8=87=B4=E6=B0=B8?= =?UTF-8?q?=E8=BF=9C=E5=8C=B9=E9=85=8D=E4=B8=8D=E5=88=B0=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 部署实测抓到: 工单TK0002状态human_pending且assignee_role=owner.maintainer, 但provider用owner.maintainer角色查待办返回0条。 根因: 动态IN子句拼接时 ph 生成的是字面量 'r0' 而非 sqlor 的参数占位格式, 渲染出的SQL是 assignee_role IN ('r0') 恒不匹配任何真实角色值, params里设置的 r0=owner.maintainer 从未被SQL引用。 两处同款错: - todos.py 角色池待办条件(human_pending且assignee_role在我的角色) - core.py list_staff_tickets 的 pending 队列条件 修法: 占位符改为 sqlor 的标准参数格式(dollar-brace-key-brace-dollar)。 渲染SQL现为 assignee_role IN (参数占位) 正确绑定。 教训: sqlor 动态 IN 子句拼接, 占位符必须用标准参数格式, 裸引号包键名会变成SQL字面量常量, 静默匹配0行不报错——极难排查。 --- ticket/core.py | 2 +- ticket/todos.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ticket/core.py b/ticket/core.py index 9f6d04f..32be136 100644 --- a/ticket/core.py +++ b/ticket/core.py @@ -545,7 +545,7 @@ async def list_staff_tickets(user_id, roles=None, queue='all', limit=100): if queue == 'pending': if not roles: return [] - ph = ','.join("'role%d'" % i for i in range(len(roles))) + ph = ','.join("'${role%d}$'" % i for i in range(len(roles))) for i, r in enumerate(roles): params['role%d' % i] = r cond = ("status='human_pending' AND assignee_role IN (%s)" % ph) diff --git a/ticket/todos.py b/ticket/todos.py index 1b40c3b..54c81df 100644 --- a/ticket/todos.py +++ b/ticket/todos.py @@ -40,7 +40,7 @@ async def list_ticket_todos(user_id, roles=None, limit=100): conds.append("(assignee_id=${u}$ AND status='human_processing')") # ③ 角色池视角:待认领且受理角色∈我的角色 if roles: - ph = ','.join("'r%d'" % i for i in range(len(roles))) + ph = ','.join("'${r%d}$'" % i for i in range(len(roles))) for i, r in enumerate(roles): params['r%d' % i] = r conds.append("(status='human_pending' AND assignee_role IN (%s))" % ph)