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 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-04-29 15:57:12 +01:00
parent 125c69fb1d
commit be0bffe459
2 changed files with 5 additions and 3 deletions

View file

@ -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,

View file

@ -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