Incorrect Serialization Format for defaultDuration in BookingService
@ramsessanchez 已經在處理了。
開始於 2026年5月18日。
評估
這個 Issue 還沒有評估資料。
描述
Describe the bug
The defaultDuration field in the BookingService model is being serialized incorrectly due to the behavior of the write_timedelta_value method in the json_serialization_writer.py module.
According to the Microsoft Graph API documentation for BookingService, the defaultDuration field must be serialized as an ISO 8601 duration, e.g., P11D23H59M59.999999999999S.
However, the SDK currently serializes Python timedelta objects using the default str(timedelta) representation, which does not conform to ISO 8601. This results in requests being sent with incorrectly formatted durations and leading to 400 Graph API errors.
Relevant Code:
File: msgraph/generated/models/booking_service.py
writer.write_timedelta_value("defaultDuration", self.default_duration)
File: kiota_serialization_json/json_serialization_writer.py
def write_timedelta_value(self, key: Optional[str], value: Optional[timedelta]) -> None:
if isinstance(value, timedelta):
if key:
self.writer[key] = str(value) # <-- Incorrect format
else:
self.value = str(value)
Expected behavior
write_timedelta_value should serialize timedelta objects to valid ISO 8601 duration strings (e.g., P1DT2H3M4S), not the default str(timedelta) representation (1 day, 2:03:04).
How to reproduce
Create a BookingService object with a default_duration = timedelta(days=1, hours=2, minutes=3, seconds=4).
Serialize the object.
Observe that the serialized value for defaultDuration is "1 day, 2:03:04" instead of "P1DT2H3M4S".
SDK Version
1.33.0
Latest version known to work for scenario above?
No response
Known Workarounds
Currently manually patching the serialize method to use correct serialization
from datetime import timedelta
from isodate import duration_isoformat
from kiota_abstractions.serialization.serialization_writer import SerializationWriter
from msgraph.generated.models.booking_service import BookingService
def patch_booking_service(booking_service: BookingService) -> None:
old_serializer = booking_service.serialize
def booking_service_serializer_patch(writer: SerializationWriter) -> None:
old_serializer(writer)
if isinstance(booking_service.default_duration, timedelta):
writer.writer["defaultDuration"] = duration_isoformat(booking_service.default_duration)
booking_service.serialize = booking_service_serializer_patch
Debug output
Click to expand log
MainError(additional_data={}, code='UnknownError', details=None, inner_error=InnerError(additional_data={}, client_request_id='08e4b63d-43c0-42aa-a8ed-c42fc75cbf2a', date=datetime.datetime(2025, 6, 16, 20, 47, 57), odata_type=None, request_id='3e28d869-8972-4636-a6f6-6cc0a126bee5'), message='{"type":"https://tools.ietf.org/html/rfc9110#section-15.5.1","title":"One or more validation errors occurred.","status":400,"errors":{"":["The input was not valid."]},"traceId":"00-3e28d86989724636a6f66cc0a126bee5-3b0ff72f47b6692f-01"}', target=None)
Configuration
SDK Version: Latest (as of writing)
Python Version: 3.11+
Endpoint: /solutions/bookingBusinesses/{id}/services
Other information
Proposed Fix
Add a new utility function for ISO 8601 serialization
File: kiota_serialization_json/json_serialization_writer.py:
from isodate import duration_isoformat
def write_iso8601_duration(self, key: Optional[str], value: Optional[timedelta]) -> None:
"""
Writes a timedelta as an ISO 8601 duration string (e.g., P1DT2H3M4S).
"""
if isinstance(value, timedelta):
duration = duration_isoformat(value)
if key:
self.writer[key] = duration
else:
self.value = duration
Then update BookingService to call this new method explicitly:
File: msgraph/generated/models/booking_service.py:
@dataclass
class BookingService(Entity, Parsable):
...
def serialize(self, writer: SerializationWriter) -> None:
...
# Use the custom method for ISO 8601 durations
if hasattr(writer, "write_iso8601_duration"):
writer.write_iso8601_duration("defaultDuration", self.default_duration)
else:
writer.write_timedelta_value("defaultDuration", self.default_duration) # Fallback
- 主要語言
- Python
- 星號
- 630
- 分支
- 96
- 平均合併
- 15 小時 20 分鐘
- 30 天內合併 PR
- 3
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoftgraph/msgraph-sdk-python 的其他 Issue
-
status:waiting-for-triage type:bug
難度 1/5 1 小時以內 新手友好度 90/100
microsoftgraph/msgraph-sdk-python#1570 ·
-
status:waiting-for-triage type:bug
難度 2/5 1-3 小時 新手友好度 75/100
microsoftgraph/msgraph-sdk-python#1563 ·
-
Needs: Attention :wave: type:bug
難度 2/5 1-3 小時 新手友好度 62/100
microsoftgraph/msgraph-sdk-python#1287 · 2 則留言 · 1 個 reaction ·
-
status:waiting-for-triage type:bug
難度 3/5 1-2 天 新手友好度 52/100
microsoftgraph/msgraph-sdk-python#1578 ·
-
status:waiting-for-triage
難度 5/5 一週以上 新手友好度 25/100
microsoftgraph/msgraph-sdk-python#1557 ·
查看 microsoftgraph/msgraph-sdk-python 的全部 Issue
相似的 Issue
-
agent-ready documentation needs-triage
難度 1/5 1-3 小時 新手友好度 88/100
-
documentation
難度 1/5 1 小時以內 新手友好度 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" 未關閉
難度 1/5 1 小時以內 新手友好度 92/100
-
instance instance add
難度 1/5 1 小時以內 新手友好度 72/100
searxng/searx-instances#939 · 1 則留言 ·
-
area-deployment area-integrations triage:bot-seen
難度 2/5 半天 新手友好度 86/100