From 60315166820c414294f0b0b728eccdd097016a7b Mon Sep 17 00:00:00 2001 From: Jose Lago Date: Fri, 10 Jul 2026 23:09:42 +0200 Subject: [PATCH] fix: convert asyncpg UUIDs to strings in web UI queries --- worker/src/web.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/worker/src/web.py b/worker/src/web.py index 1664aed..cbc701e 100644 --- a/worker/src/web.py +++ b/worker/src/web.py @@ -15,24 +15,37 @@ templates = Jinja2Templates(directory="templates") async def query(sql: str, *args) -> list: - """Execute a query and return rows as dicts.""" + """Execute a query and return rows as dicts with UUIDs converted to strings.""" try: pool = await get_pool() async with pool.acquire() as conn: rows = await conn.fetch(sql, *args) - return [dict(r) for r in rows] + result = [] + for row in rows: + d = dict(row) + for k, v in d.items(): + if hasattr(v, 'hex'): # asyncpg UUID + d[k] = str(v) + result.append(d) + return result except Exception as e: logger.error("Database query error: %s", e) raise async def query_one(sql: str, *args) -> dict | None: - """Execute a query and return a single row as dict.""" + """Execute a query and return a single row as dict with UUIDs converted to strings.""" try: pool = await get_pool() async with pool.acquire() as conn: row = await conn.fetchrow(sql, *args) - return dict(row) if row else None + if not row: + return None + d = dict(row) + for k, v in d.items(): + if hasattr(v, 'hex'): # asyncpg UUID + d[k] = str(v) + return d except Exception as e: logger.error("Database query error: %s", e) raise