From f25708484b9194e80548df06f1b9793ff58ff011 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 5 Oct 2026 04:46:49 +0200 Subject: [PATCH] fix: Daily Messages chart in Analytics fails to load on All time when a message has no timestamp (#31888) With All time selected, the Daily Messages chart in Admin Panel > Analytics failed to load (the daily analytics request returned a 500) as soon as one message had been saved without a timestamp, for example a chat created through the API with a null timestamp. A date range still worked because those messages were left out of it. Such messages now get the time they were saved, and ones already stored without a timestamp are counted on today's date instead of breaking the chart. Messages that came after the missing timestamp in the same chat were also left out of analytics before and are now counted. Fixes #27316 --- backend/open_webui/models/chat_messages.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/models/chat_messages.py b/backend/open_webui/models/chat_messages.py index 7ccbba7a87..145213b8b7 100644 --- a/backend/open_webui/models/chat_messages.py +++ b/backend/open_webui/models/chat_messages.py @@ -31,9 +31,11 @@ from sqlalchemy.ext.asyncio import AsyncSession #################### -def _normalize_timestamp(timestamp: int) -> float: +def _normalize_timestamp(timestamp: Optional[int]) -> float: """Normalize and validate timestamp. Returns current time if invalid.""" now = time.time() + if timestamp is None: + return now # Convert milliseconds to seconds if needed if timestamp > 10_000_000_000: @@ -263,7 +265,7 @@ class ChatMessageTable: error=data.get('error'), usage=get_usage(data), context_summary=data.get('context_summary') or data.get('contextSummary'), - created_at=data.get('timestamp', now), + created_at=data.get('timestamp') or now, updated_at=now, )