Files
DadaoTask/backend/alembic/versions/0015_bot_channel_policy_nullif.py
T
Steven 1e8cd01b3d
CI / backend (push) Canceled after 0s
fix(integrations): 扫码确认后不再 500,回话不带链接,栏目改叫「机器人」
1. 扫码确认那一刻页面报「服务器内部错误」:`bot_channel` 的轮询口子直接
   `current_setting('app.bot_channel', true)::uuid`,而事务级 set_config 提交后
   会把连接上的变量还原成空串而不是 NULL,空串 cast 就 InvalidTextRepresentation。
   迁移 0015 改成 nullif(...,'')::uuid,与 app_ws_id() 同一写法。
2. 微信回话只回「已保存任务:…」/「已保存知识草稿:…」,不再带站点链接
   (PUBLIC_BASE_URL 是内网地址,手机上打不开)。
3. 栏目名「接入」改名「机器人」;页面标题与提示文案同步。

pytest 151 passed;ruff check/format 干净;tsc 0;vite build 通过;
web/e2e/integrations.mjs 7 项全绿。
2026-11-05 23:22:49 +08:00

57 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""bot_channel 的轮询口子要容忍"空字符串"的 GUC
`set_config(..., true)` 提交后会把变量还原成上一次的值;连接池里这条连接如果本来没有
会话级值,还原出来的是空串 `''` 而不是 NULL。`0014` 的策略直接
`current_setting('app.bot_channel', true)::uuid`,空串一 cast 就
`InvalidTextRepresentationError: invalid input syntax for type uuid: ""`,
于是同一连接上下一个请求(比如扫码确认)500。
这里把策略重建成和 `app_ws_id()` 一样的写法:先 `nullif(..., '')` 再 cast。
Revision ID: 0015
Revises: 0014
"""
from __future__ import annotations
from alembic import op
from app.roles import APP_ROLE
revision = "0015"
down_revision = "0014"
branch_labels = None
depends_on = None
STATEMENTS: tuple[str, ...] = (
"DROP POLICY IF EXISTS bot_channel_worker ON bot_channel",
"""
CREATE POLICY bot_channel_worker ON bot_channel
FOR ALL
USING (
id = nullif(current_setting('app.bot_channel', true), '')::uuid
)
WITH CHECK (
id = nullif(current_setting('app.bot_channel', true), '')::uuid
)
""",
f"GRANT SELECT, INSERT, UPDATE, DELETE ON bot_channel TO {APP_ROLE}",
)
def upgrade() -> None:
for statement in STATEMENTS:
op.execute(statement)
def downgrade() -> None:
op.execute("DROP POLICY IF EXISTS bot_channel_worker ON bot_channel")
op.execute(
"""
CREATE POLICY bot_channel_worker ON bot_channel
FOR ALL
USING (id = current_setting('app.bot_channel', true)::uuid)
WITH CHECK (id = current_setting('app.bot_channel', true)::uuid)
"""
)