Skip to content

Time are messed up in Chainlit #2491

@asvishnyakov

Description

@asvishnyakov

Describe the bug

timestamp = await self.get_current_timestamp()
created_at = step_dict.get("createdAt")
if created_at:
timestamp = datetime.strptime(created_at, ISO_FORMAT)

Saves in UTC (with Z), but

createdAt=row["createdAt"].isoformat() if row.get("createdAt") else None,

reads in local time (without Z)

and when system tries to save it again we get exception

2025-09-03 22:00:48 - Task exception was never retrieved
future: <Task finished name='Task-1150' coro=<ChainlitDataLayer.update_step() done, defined at /Users/dmitriy/Documents/GitHub/cookbook/resume-chat/.venv/lib/python3.13/site-packages/chainlit/data/utils.py:10> exception=ValueError("time data '2025-09-04T02:00:42.164000' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'")>
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/tasks.py", line 304, in __step_run_and_handle_result
    result = coro.send(None)
  File "/Users/dmitriy/Documents/GitHub/cookbook/resume-chat/.venv/lib/python3.13/site-packages/chainlit/data/utils.py", line 25, in wrapper
    return await method(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dmitriy/Documents/GitHub/cookbook/resume-chat/.venv/lib/python3.13/site-packages/chainlit/data/chainlit_data_layer.py", line 388, in update_step
    await self.create_step(step_dict)
  File "/Users/dmitriy/Documents/GitHub/cookbook/resume-chat/.venv/lib/python3.13/site-packages/chainlit/data/utils.py", line 25, in wrapper
    return await method(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dmitriy/Documents/GitHub/cookbook/resume-chat/.venv/lib/python3.13/site-packages/chainlit/data/chainlit_data_layer.py", line 368, in create_step
    timestamp = datetime.strptime(created_at, ISO_FORMAT)
  File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_strptime.py", line 674, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_strptime.py", line 453, in _strptime
    raise ValueError("time data %r does not match format %r" %
                     (data_string, format))
ValueError: time data '2025-09-04T02:00:42.164000' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'

when returned back to data layer and it tries to update thread step

To Reproduce
See #2486

Expected behavior
UTC should be saved returned

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdata layerPertains to data layers.keep-for-a-whileDon’t mark as stale. This label should be used only for confirmed bugs or other important things

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions