Skip to content

Duration readers cannot round-trip native timedelta writer output #871

Closed

Description

@Muneer320

Problem

The serialization writers use str(timedelta) for duration values, but the shared duration reader only accepts ISO8601 strings and the legacy hh:mm[:ss] form. Python's native representation adds a day prefix and/or fractional seconds for other values, which the reader rejects.

Examples from current main (2d0360710c6ee48f4b1a9f805c5d3d8302c935e2):

from datetime import timedelta
from kiota_abstractions.date_utils import parse_timedelta_string

value = timedelta(days=2, microseconds=1)
print(str(value))  # '2 days, 0:00:00.000001'
assert parse_timedelta_string(str(value)) == value

The assertion cannot be reached because parsing raises ValueError. This also affects a positive microsecond, a negative duration such as timedelta(microseconds=-1), and timedelta.max / timedelta.min.

The JSON and form writers emit the string but their readers return None; the text reader raises. Whole-hour durations such as 2:00:00 still work.

A focused fix can extend the existing native-format fallback to accept the optional signed day prefix and up to six fractional-second digits, using integer day/second/microsecond components. Existing serialized content and the ISO parser can remain unchanged. This is separate from #867's ISO component-presence validation.

Activity

  1. moved this to Needs Triage 🔍 in Kiotaon Nov 7, 2026
  2. moved this from Needs Triage 🔍 to Done ✔️ in Kiotaon Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done ✔️

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions