Skip to content

bug(sdk-python): datetime.time and timedelta values are recorded as "<time>" and "<timedelta>" #20158

Open
langfuse/langfuse-python
#2131

Description

@MaiAditya

Describe the bug

EventSerializer handles date and datetime but not datetime.time or timedelta, so both fall through to the type-name fallback and the value is lost. This also affects pydantic models with such fields, since their model_dump() output goes back through the serializer.

Expected: the actual values are recorded.

Steps to reproduce

import datetime as dt
import json
from langfuse._utils.serializer import EventSerializer

print(json.dumps({"at": dt.time(9, 30), "timeout": dt.timedelta(seconds=90)}, cls=EventSerializer))
{"at": "<time>", "timeout": "<timedelta>"}

Langfuse Cloud or self-hosted?

Not applicable: this reproduces in the Python SDK alone, no server needed.

SDK and integration versions

langfuse 5.2.0 (same code on langfuse-python main 00e5098), Python 3.12

Additional information

Issues are closed on langfuse/langfuse-python, so I'm filing it here.

Are you interested in contributing a fix for this bug?

Yes. I have a fix with tests ready and will open a PR on langfuse-python linked to this issue: time as isoformat() like date/datetime, and timedelta as a number of seconds (or an ISO 8601 duration such as PT1M30S, if you prefer that).

Activity

  1. ShayanMuhammad-CS commented on Nov 15, 2026

    @ShayanMuhammad-CS

    I have opened PR #2131 on langfuse-python resolving this issue.

    Summary:

    • Added datetime.time serialization via obj.isoformat()
    • Added datetime.timedelta serialization via obj.total_seconds()
    • Added 6 unit tests covering ISO strings, microsecond/timezone offsets, negative and fractional timedeltas, and nested Pydantic models containing time and timedelta fields. All 8 serializer datetime test suites are passing cleanly.
  2. MaiAditya commented on Nov 16, 2026

    @MaiAditya
    Author

    Thanks for the interest, @ShayanMuhammad-CS. I filed this issue together with #20157 and have the fix and its tests ready on this branch (time via isoformat() like date/datetime, timedelta as total seconds). I only held back the PR to keep one open at a time while langfuse/langfuse-python#2127 is in review.

    I'd like to carry this one through myself, unless @hassiebp would rather go with #2131. I'm happy to open my PR right away if that's easier to review.

  3. ShayanMuhammad-CS commented on Nov 18, 2026

    @ShayanMuhammad-CS

    Thanks @MaiAditya! @chrikrah has reviewed PR #2131 on langfuse-python and suggested formatting \ imedelta\ as standard ISO 8601 duration strings (\PT5M) for consistency with Pydantic's \model_dump_json(). That update has been implemented and verified across all test cases. Very happy to collaborate if there are any additional edge-case tests from your branch that we should include!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions