fix(data): use UTC for timestamps in SQLAlchemy data layer#2923
Open
hobostay wants to merge 1 commit into
Open
fix(data): use UTC for timestamps in SQLAlchemy data layer#2923hobostay wants to merge 1 commit into
hobostay wants to merge 1 commit into
Conversation
`get_current_timestamp()` used `datetime.now()` which returns local time, but appended "Z" (the UTC timezone designator). This produced incorrect timestamps when the server was not running in UTC. Use `datetime.now(timezone.utc)` to ensure the timestamp is actually in UTC before appending "Z". Related: Chainlit#2491 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/chainlit/data/sql_alchemy.py">
<violation number="1" location="backend/chainlit/data/sql_alchemy.py:106">
P1: UTC-aware isoformat() output incorrectly appends 'Z', producing invalid timestamps with both '+00:00' and 'Z'</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
|
||
| async def get_current_timestamp(self) -> str: | ||
| return datetime.now().isoformat() + "Z" | ||
| return datetime.now(timezone.utc).isoformat() + "Z" |
Contributor
There was a problem hiding this comment.
P1: UTC-aware isoformat() output incorrectly appends 'Z', producing invalid timestamps with both '+00:00' and 'Z'
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/chainlit/data/sql_alchemy.py, line 106:
<comment>UTC-aware isoformat() output incorrectly appends 'Z', producing invalid timestamps with both '+00:00' and 'Z'</comment>
<file context>
@@ -103,7 +103,7 @@ async def execute_sql(
async def get_current_timestamp(self) -> str:
- return datetime.now().isoformat() + "Z"
+ return datetime.now(timezone.utc).isoformat() + "Z"
def clean_result(self, obj):
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_current_timestamp()inSQLAlchemyDataLayerto usedatetime.now(timezone.utc)instead ofdatetime.now().Why
The method
get_current_timestamp()useddatetime.now()which returns local time, but then appended"Z"(the ISO 8601 UTC designator). This resulted in timestamps that claimed to be UTC but were actually in the server's local timezone.For example, on a server running in UTC+8 (China Standard Time), a timestamp at 2pm local would be stored as
2026-05-10T14:00:00.000000Z, implying 2pm UTC when it should be 6am UTC.This bug affects:
createdAt)Related issue: #2491 (time handling mismatch causes exceptions)
Test plan
uv run pytest tests/frombackend/🤖 Generated with Claude Code
Summary by cubic
Fix timestamp timezone handling in the SQLAlchemy data layer by generating UTC-aware ISO strings in
get_current_timestamp(). EnsurescreatedAtand thread timestamps are true UTC instead of local time labeled as Z, addressing #2491.Written for commit 07bbb40. Summary will update on new commits.