fix: Datetime format mismatch causing a bug in chainlit_data_layer.py#2821
Closed
jakubgajski wants to merge 5 commits intoChainlit:mainfrom
Closed
fix: Datetime format mismatch causing a bug in chainlit_data_layer.py#2821jakubgajski wants to merge 5 commits intoChainlit:mainfrom
jakubgajski wants to merge 5 commits intoChainlit:mainfrom
Conversation
…rings for compliance with widely used utc_now() from backend/chainlit/utils.py
…ce with `Z` suffix - Added tests to ensure `createdAt`, `startTime`, and `endTime` align with `utc_now()` compliance. - Verified `Z` suffix is present across `get_user`, `create_user`, `list_threads`, `get_thread`, and `_convert_step_row_to_dict`. - Added coverage for handling `None` timestamps in `_convert_step_row_to_dict`.
Collaborator
|
Thanks for the contrib. However, this seems a dup of #2798. If I am wrong, please, reopen! |
Collaborator
|
The other (approved) PR is just pending merge conflicts. Feel free to solve them and shoot a new PR yourself. Or poke the original author. :) |
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.
Problem
The ChainlitDataLayer methods were generating ISO-formatted datetime strings without the Z suffix (e.g., 2026-03-02T11:54:54.670000), while the widely-used utc_now() utility function in backend/chainlit/utils.py consistently produces timestamps with the Z suffix (e.g., 2026-03-02T11:54:54.670000Z).
This inconsistency caused ValueError exceptions when parsing datetime strings:
While the original log was:
Solution
Added Z suffix to all ISO-formatted datetime strings in ChainlitDataLayer to ensure consistency with the utc_now() format used throughout the codebase.
Modified methods:
get_user() - line 98
create_user() - line 124
list_threads() - line 500
get_thread() - line 564
_convert_step_row_to_dict() - lines 684, 687, 689 (for createdAt, start, and end fields)
Changes
Fix (cc120b7): Modified 6 locations in chainlit_data_layer.py to append "Z" to .isoformat() calls
Tests (b7ebd72): Added comprehensive test coverage (206 lines) verifying:
Impact
Prevents ValueError exceptions during datetime parsing
Ensures consistent UTC timezone representation across the data layer
Maintains compatibility with existing parsing logic that expects the Z suffix
Summary by cubic
Standardize datetime strings in
ChainlitDataLayerby appending the "Z" suffix to ISO timestamps to matchutc_now(). This prevents parsing errors and ensures all timestamps are UTC.Written for commit 3e25918. Summary will update on new commits.