v1.0.170: fix prompts list — datetime serialization

This commit is contained in:
2026-06-24 13:32:13 +04:00
parent e2348eaf4e
commit 15bd4ad322
+13 -2
View File
@@ -2,12 +2,19 @@
from .connection import query, execute, execute_returning from .connection import query, execute, execute_returning
def _serialize(row):
"""Convert datetime fields to strings for JSON serialization."""
if row and row.get("created_at"):
row["created_at"] = str(row["created_at"])
return row
def get_active(role): def get_active(role):
rows = query( rows = query(
"SELECT * FROM prompts WHERE role = %s AND is_active = true ORDER BY created_at DESC LIMIT 1", "SELECT * FROM prompts WHERE role = %s AND is_active = true ORDER BY created_at DESC LIMIT 1",
(role,), (role,),
) )
return rows[0] if rows else None return _serialize(rows[0]) if rows else None
def get(prompt_id): def get(prompt_id):
@@ -40,10 +47,14 @@ def seed_defaults():
def list_by_role(role): def list_by_role(role):
"""List all versions for a role, newest first.""" """List all versions for a role, newest first."""
return query( rows = query(
"SELECT id, role, name, is_active, created_by, notes, created_at FROM prompts WHERE role=%s ORDER BY created_at DESC", "SELECT id, role, name, is_active, created_by, notes, created_at FROM prompts WHERE role=%s ORDER BY created_at DESC",
(role,), (role,),
) )
for r in rows:
if r.get("created_at"):
r["created_at"] = str(r["created_at"])
return rows
def save_new_version(role, name, body, notes="", is_active=True): def save_new_version(role, name, body, notes="", is_active=True):