Commit 6289082f authored by Vũ Hoàng Anh's avatar Vũ Hoàng Anh

fix: handle None created_at in lead_flow_postgres to prevent isoformat AttributeError

parent 679f76a1
...@@ -169,7 +169,7 @@ async def get_lead_history( ...@@ -169,7 +169,7 @@ async def get_lead_history(
"id": r["id"], "id": r["id"],
"is_human": r["is_human"], "is_human": r["is_human"],
"message": r["message"], "message": r["message"],
"timestamp": r["created_at"] if isinstance(r["created_at"], str) else r["created_at"].isoformat(), "timestamp": (r["created_at"] if isinstance(r["created_at"], str) else r["created_at"].isoformat()) if r["created_at"] else "",
"conversation_id": conv_id, "conversation_id": conv_id,
} }
for r in rows for r in rows
...@@ -199,7 +199,7 @@ async def get_lead_history( ...@@ -199,7 +199,7 @@ async def get_lead_history(
"id": r["id"], "id": r["id"],
"is_human": r["is_human"], "is_human": r["is_human"],
"message": r["message"], "message": r["message"],
"timestamp": r["created_at"].isoformat(), "timestamp": r["created_at"].isoformat() if r["created_at"] else "",
"conversation_id": conv_id, "conversation_id": conv_id,
} }
for r in rows for r in rows
...@@ -238,8 +238,8 @@ async def list_lead_conversations(device_id: str, limit: int = 20) -> list[dict] ...@@ -238,8 +238,8 @@ async def list_lead_conversations(device_id: str, limit: int = 20) -> list[dict]
return [ return [
{ {
"conv_id": r["conv_id"], "conv_id": r["conv_id"],
"started_at": r["started_at"] if isinstance(r["started_at"], str) else r["started_at"].isoformat(), "started_at": (r["started_at"] if isinstance(r["started_at"], str) else r["started_at"].isoformat()) if r["started_at"] else "",
"last_at": r["last_at"] if isinstance(r["last_at"], str) else r["last_at"].isoformat(), "last_at": (r["last_at"] if isinstance(r["last_at"], str) else r["last_at"].isoformat()) if r["last_at"] else "",
"turn_count": r["turn_count"], "turn_count": r["turn_count"],
} }
for r in rows for r in rows
...@@ -271,8 +271,8 @@ async def list_lead_conversations(device_id: str, limit: int = 20) -> list[dict] ...@@ -271,8 +271,8 @@ async def list_lead_conversations(device_id: str, limit: int = 20) -> list[dict]
return [ return [
{ {
"conv_id": r["conv_id"], "conv_id": r["conv_id"],
"started_at": r["started_at"].isoformat(), "started_at": r["started_at"].isoformat() if r["started_at"] else "",
"last_at": r["last_at"].isoformat(), "last_at": r["last_at"].isoformat() if r["last_at"] else "",
"turn_count": r["turn_count"], "turn_count": r["turn_count"],
} }
for r in rows for r in rows
...@@ -312,7 +312,7 @@ async def get_all_history_for_dashboard(limit: int = 200) -> list[dict]: ...@@ -312,7 +312,7 @@ async def get_all_history_for_dashboard(limit: int = 200) -> list[dict]:
"ai_response": r["ai_response"], "ai_response": r["ai_response"],
"products": r["products"], "products": r["products"],
"lead_stage": r["lead_stage"], "lead_stage": r["lead_stage"],
"created_at": r["created_at"] if isinstance(r["created_at"], str) else r["created_at"].isoformat(), "created_at": (r["created_at"] if isinstance(r["created_at"], str) else r["created_at"].isoformat()) if r["created_at"] else "",
} }
for r in rows for r in rows
] ]
...@@ -346,7 +346,7 @@ async def get_all_history_for_dashboard(limit: int = 200) -> list[dict]: ...@@ -346,7 +346,7 @@ async def get_all_history_for_dashboard(limit: int = 200) -> list[dict]:
"ai_response": r["ai_response"], "ai_response": r["ai_response"],
"products": r["products"], "products": r["products"],
"lead_stage": r["lead_stage"], "lead_stage": r["lead_stage"],
"created_at": r["created_at"].isoformat(), "created_at": r["created_at"].isoformat() if r["created_at"] else "",
} }
for r in rows for r in rows
] ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment