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
This commit is contained in:
Classic298 2026-10-05 04:46:49 +02:00 • committed by GitHub
parent c5dac0070d
commit f25708484b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,
)