Skip to content

Commit

Permalink
Merge pull request #404 from microsoft/bumpSTDLib
Browse files Browse the repository at this point in the history
fix: fixes date-time in requests to align with std-uritemplate 2.0.0
  • Loading branch information
andrueastman authored Nov 11, 2024
2 parents d700d67 + b304bed commit 58be436
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions packages/abstractions/kiota_abstractions/request_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

from dataclasses import fields, is_dataclass
from datetime import date, datetime, time, timedelta
from datetime import date, datetime, time, timedelta, timezone
from enum import Enum
from io import BytesIO
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Set, TypeVar, Union
Expand Down Expand Up @@ -298,7 +298,14 @@ def _get_sanitized_value(self, value: Any) -> Any:
elif isinstance(value, list) and all(isinstance(x, Enum) for x in value):
sanitized_value = ','.join([x.value for x in value])
elif isinstance(value, datetime):
sanitized_value = value
timezone_info = value.tzinfo
if timezone_info is None:
timezone_info = timezone.utc
temp_date_with_tz_info = datetime(
value.year, value.month, value.day, value.hour, value.minute, value.second,
value.microsecond, timezone_info
)
sanitized_value = temp_date_with_tz_info.isoformat("T")
elif any([isinstance(value, UUID), isinstance(value, date), isinstance(value, time)]):
sanitized_value = str(value)
return sanitized_value
Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ include = ["CHANGELOG.md", "LICENSE"]

[tool.poetry.dependencies]
python = ">=3.8,<4.0"
std-uritemplate = ">=0.0.38,<2.0.0"
std-uritemplate = ">=2.0.0"
opentelemetry-api = ">=1.27.0"
opentelemetry-sdk = ">=1.27.0"

Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/tests/test_request_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_sets_datetime_values_in_path_parameters():
"""
request_info = RequestInformation(Method.GET, "https://example.com/daysFrom/{startDate}")
request_info.path_parameters["startDate"] = datetime(year=2020, month=8, day=1, hour=0, minute=20, second=0, microsecond=0)
assert request_info.url == "https://example.com/daysFrom/2020-08-01T00%3A20%3A00Z"
assert request_info.url == "https://example.com/daysFrom/2020-08-01T00%3A20%3A00%2B00%3A00"

def test_sets_int_values_in_path_parameters():
"""Tests setting int values values in path parameters
Expand Down

0 comments on commit 58be436

Please sign in to comment.