diff --git a/modules/interfaces/interfaceDbChat.py b/modules/interfaces/interfaceDbChat.py index cd688ca7..dfdf9886 100644 --- a/modules/interfaces/interfaceDbChat.py +++ b/modules/interfaces/interfaceDbChat.py @@ -909,9 +909,10 @@ class ChatObjects: "actionProgress": msg.get("actionProgress") }) - # Apply default sorting by publishedAt if no sort specified + # Apply default sorting by publishedAt if no sort specified. + # Use parseTimestamp to tolerate mixed DB types (float/string) on INT. if pagination is None or not pagination.sort: - messageDicts.sort(key=lambda x: x.get("publishedAt") or getUtcTimestamp()) + messageDicts.sort(key=lambda x: parseTimestamp(x.get("publishedAt"), default=0)) # Apply filtering (if filters provided) if pagination and pagination.filters: @@ -1537,9 +1538,10 @@ class ChatObjects: if not stats: return [] - # Return all stats records sorted by creation time - # DB uses _createdAt (camelCase system field) - stats.sort(key=lambda x: x.get("_createdAt", 0)) + # Return all stats records sorted by creation time. + # Use parseTimestamp to tolerate mixed DB types (float/string) on INT. + # DB uses _createdAt (camelCase system field). + stats.sort(key=lambda x: parseTimestamp(x.get("_createdAt"), default=0)) # Convert to ChatStat objects, preserving _createdAt via extra="allow" result = []