fix(library): library-neighbors JSONB cast 오류 — EXISTS 서브쿼리로 교체

This commit is contained in:
Hyungi Ahn
2026-04-27 12:43:26 +09:00
parent e92bf3c06b
commit 6e3ce91de6
+9 -2
View File
@@ -559,14 +559,21 @@ async def get_library_neighbors(
if not path:
return LibraryNeighborsResponse(prev=None, next=None, path=None)
# 같은 path (정확히) 의 자료들 — title 오름차순
# 같은 path (정확히) 의 자료들 — title 오름차순.
# user_tags 는 JSONB. 다른 endpoint 와 일관되게 EXISTS + jsonb_array_elements_text 사용.
from sqlalchemy import text as sql_text
exact_tag = f"{LIBRARY_PREFIX}{path}"
res = await session.execute(
select(Document.id, Document.title)
.where(
Document.deleted_at == None, # noqa: E711
Document.category == "library",
Document.user_tags.op("@>")(f'["{exact_tag}"]'),
sql_text("""
EXISTS (
SELECT 1 FROM jsonb_array_elements_text(documents.user_tags) AS t
WHERE t = :exact
)
""").bindparams(exact=exact_tag),
)
.order_by(Document.title.asc().nullslast(), Document.id.asc())
)