From 8b7a93d58f957d4e6403c5fb8a4ad2b169fdbd31 Mon Sep 17 00:00:00 2001 From: Clawd Date: Thu, 5 Mar 2026 22:13:39 +0000 Subject: [PATCH] Fix frontmatter dict conversion in documents router --- services/rag-api/routers/documents.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/services/rag-api/routers/documents.py b/services/rag-api/routers/documents.py index 770eeac..f5db55f 100644 --- a/services/rag-api/routers/documents.py +++ b/services/rag-api/routers/documents.py @@ -52,12 +52,22 @@ async def related_documents(document_id: str, limit: int = 5): def _row_to_doc(row: asyncpg.Record) -> DocumentResponse: + # Handle frontmatter - asyncpg returns JSONB as dict directly + fm = row['frontmatter'] + if fm is None: + frontmatter = {} + elif isinstance(fm, dict): + frontmatter = fm + else: + # Fallback for unexpected types + frontmatter = {} + return DocumentResponse( id=str(row['id']), path=row['path'], title=row['title'] or '', content=row['content'], - frontmatter=dict(row['frontmatter'] or {}), + frontmatter=frontmatter, tags=list(row['tags'] or []), aliases=list(row['aliases'] or []), word_count=row['word_count'],