From be0bffe459f9563ba68eeda97dbb83c0ec2e4ab6 Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Wed, 29 Apr 2026 15:57:12 +0100 Subject: [PATCH] fix: get_terms_page avoids GlossaryTerm validation on partial projection Projected docs only have _id/source_term/translations; validating against GlossaryTerm (which requires glossary_id, version_id, source_term_lower) caused 500 on the terms endpoint. Return plain dicts instead. Co-Authored-By: Claude Sonnet 4.6 --- backend/app/api/v1/routes_glossaries.py | 2 +- backend/app/services/glossary_service.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/app/api/v1/routes_glossaries.py b/backend/app/api/v1/routes_glossaries.py index 5eaf993..2f53979 100644 --- a/backend/app/api/v1/routes_glossaries.py +++ b/backend/app/api/v1/routes_glossaries.py @@ -137,7 +137,7 @@ async def list_terms( terms, total = await svc.get_terms_page(vid, search=search, page=page, page_size=page_size) return { - "terms": [{"source_term": t.source_term, "translations": t.translations} for t in terms], + "terms": [{"source_term": t["source_term"], "translations": t["translations"]} for t in terms], "total": total, "page": page, "page_size": page_size, diff --git a/backend/app/services/glossary_service.py b/backend/app/services/glossary_service.py index 5c96742..18d7b39 100644 --- a/backend/app/services/glossary_service.py +++ b/backend/app/services/glossary_service.py @@ -713,7 +713,7 @@ async def get_terms_page( search: str | None = None, page: int = 1, page_size: int = 50, -) -> tuple[list[GlossaryTerm], int]: +) -> tuple[list[dict], int]: """Returns (terms, total_count) for paginated UI preview.""" db = await get_database() query: dict = {"version_id": version_id} @@ -732,5 +732,7 @@ async def get_terms_page( terms = [] for d in docs: d["_id"] = str(d["_id"]) - terms.append(GlossaryTerm.model_validate(d)) + # Only source_term + translations are projected — build a minimal dict + # rather than validating against GlossaryTerm (which requires more fields) + terms.append({"_id": d["_id"], "source_term": d.get("source_term", ""), "translations": d.get("translations", {})}) return terms, total