From 7f95084d7611847595ac1b1fa15a68380839664e Mon Sep 17 00:00:00 2001 From: "34047007@qq.com" <34047007@qq.com> Date: Mon, 10 Aug 2026 17:49:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=90=9C=E7=B4=A2=20tag=20=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E6=94=B9=E7=94=A8=20cast(ARRAY(Uuid))=EF=BC=8C?= =?UTF-8?q?=E6=9D=9C=E7=BB=9D=20asyncpg=20=E6=8A=8A=20ARRAY[$n]=20?= =?UTF-8?q?=E6=8E=A8=E6=96=AD=E6=88=90=20text[]=20=E5=AF=BC=E8=87=B4=20uui?= =?UTF-8?q?d[]=20&&=20text[]=20500=EF=BC=88=E6=A0=B9=E5=9B=A0=E5=9C=A8=20y?= =?UTF-8?q?ear=5Fcounts=20=E5=AD=90=E6=9F=A5=E8=AF=A2=E5=A4=8D=E7=94=A8=20?= =?UTF-8?q?conditions=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/search_engine.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/app/services/search_engine.py b/backend/app/services/search_engine.py index 6bdefff..d37cf62 100644 --- a/backend/app/services/search_engine.py +++ b/backend/app/services/search_engine.py @@ -4,7 +4,7 @@ import logging import re from datetime import datetime -from sqlalchemy import String, and_, case, cast, exists, func, literal_column, not_, or_, select, text +from sqlalchemy import ARRAY, String, Uuid, and_, case, cast, exists, func, literal_column, not_, or_, select, text logger = logging.getLogger(__name__) from sqlalchemy.ext.asyncio import AsyncSession @@ -506,9 +506,11 @@ class AdvancedSearchEngine: child_conds = [GlobalTag.path.like(f"{p}%") for p in paths] children = (await db.execute(select(GlobalTag.id).where(or_(*child_conds)))).scalars().all() all_tag_ids.update(children) - uids = list(all_tag_ids) - from sqlalchemy.dialects.postgresql import array as _pg_array, UUID as _pg_uuid - conditions.append(GlobalLiterature.tag_ids.overlap(_pg_array(uids, type_=_pg_uuid()))) + uids = [_uuid.UUID(u) if isinstance(u, str) else u for u in all_tag_ids] + # 显式 cast 到 ARRAY(Uuid):不依赖 _pg_array 的参数类型推断(asyncpg prepared + # statement 会把 ARRAY[$n] 推断成 text[],导致 uuid[] && text[] 500)。cast 后 + # 编译产物必带 ::uuid[],杜绝推断漂移。 + conditions.append(GlobalLiterature.tag_ids.overlap(cast(uids, ARRAY(Uuid)))) # 发表类型(PG JSONB contains) if pub_types: