fix: convert asyncpg UUIDs to strings in web UI queries
CI / lint-and-test (push) Has been cancelled

This commit is contained in:
2026-07-10 23:09:42 +02:00
parent 8e5e45e204
commit 6031516682
+17 -4
View File
@@ -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