fix(site-import): config_json Text 列 JSON 串反序列化(生产走查抓漏——str 传 resolver 炸 .get)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-10-21 09:36:22 +08:00
parent c2ccf8b1ae
commit 6dacb8f432
+8 -1
View File
@@ -18,6 +18,8 @@
启动只做校验+建任务——pipeline 由任务模块的后台 aio task 跑,本层不 启动只做校验+建任务——pipeline 由任务模块的后台 aio task 跑,本层不
感知 crawler/generator(测试也因此能整体打桩 task.start/task.get)。 感知 crawler/generator(测试也因此能整体打桩 task.start/task.get)。
""" """
import json
from fastapi import APIRouter, Depends, HTTPException, Request from fastapi import APIRouter, Depends, HTTPException, Request
from pydantic import BaseModel from pydantic import BaseModel
from sqlalchemy import select from sqlalchemy import select
@@ -45,11 +47,16 @@ async def start_import(slug: str, body: StartRequest, request: Request,
tenant = await _get_tenant_or_404(session, slug) tenant = await _get_tenant_or_404(session, slug)
# 租户配置快照(终审 Important #2:AI 三级链的租户槽位——传给 # 租户配置快照(终审 Important #2:AI 三级链的租户槽位——传给
# task.start → make_provider;自有 ai.* 配置的租户烧自己配额) # task.start → make_provider;自有 ai.* 配置的租户烧自己配额)
latest = (await session.execute( # config_json 列为 Text——scalar 返回 JSON 串,须 json.loads 成 dict
raw_config = (await session.execute(
select(TenantConfigVersion.config_json) select(TenantConfigVersion.config_json)
.where(TenantConfigVersion.tenant_id == tenant.id) .where(TenantConfigVersion.tenant_id == tenant.id)
.order_by(TenantConfigVersion.version.desc()) .order_by(TenantConfigVersion.version.desc())
.limit(1))).scalar_one_or_none() .limit(1))).scalar_one_or_none()
try:
latest = json.loads(raw_config) if raw_config else None
except (TypeError, json.JSONDecodeError):
latest = None
if tenant.status != "active": if tenant.status != "active":
raise HTTPException( raise HTTPException(
status_code=403, detail=f"租户 {slug!r} 已停用,无法发起导入") status_code=403, detail=f"租户 {slug!r} 已停用,无法发起导入")