From 6714ba8b3c48d70d7610801e6ed3077a3298949e Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Tue, 10 Sep 2024 12:47:07 +0300 Subject: [PATCH 1/4] remove is four digit number check --- kiota_serialization_json/json_parse_node.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/kiota_serialization_json/json_parse_node.py b/kiota_serialization_json/json_parse_node.py index ac3252e..ad7b09c 100644 --- a/kiota_serialization_json/json_parse_node.py +++ b/kiota_serialization_json/json_parse_node.py @@ -293,10 +293,6 @@ def _assign_field_values(self, item: U) -> None: deserialize but the model doesn't support additional data" ) - def __is_four_digit_number(self, value: str) -> bool: - pattern = r'^\d{4}$' - return bool(re.match(pattern, value)) - def try_get_anything(self, value: Any) -> Any: if isinstance(value, (int, float, bool)) or value is None: return value @@ -306,8 +302,6 @@ def try_get_anything(self, value: Any) -> Any: return dict(map(lambda x: (x[0], self.try_get_anything(x[1])), value.items())) if isinstance(value, str): try: - if self.__is_four_digit_number(value): - return value datetime_obj = pendulum.parse(value) if isinstance(datetime_obj, pendulum.Duration): From 6544b52d3e78e28db6c7036c65423906fd8e22c5 Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Tue, 10 Sep 2024 12:50:54 +0300 Subject: [PATCH 2/4] add check for isdidgit --- kiota_serialization_json/json_parse_node.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kiota_serialization_json/json_parse_node.py b/kiota_serialization_json/json_parse_node.py index ad7b09c..937ccd3 100644 --- a/kiota_serialization_json/json_parse_node.py +++ b/kiota_serialization_json/json_parse_node.py @@ -302,7 +302,8 @@ def try_get_anything(self, value: Any) -> Any: return dict(map(lambda x: (x[0], self.try_get_anything(x[1])), value.items())) if isinstance(value, str): try: - + if value.isdigit(): + return value datetime_obj = pendulum.parse(value) if isinstance(datetime_obj, pendulum.Duration): return datetime_obj.as_timedelta() From 083a173f5a0f4a7998bbe9feea0c98fc68856c10 Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Tue, 10 Sep 2024 13:00:26 +0300 Subject: [PATCH 3/4] add unit tests --- tests/unit/test_json_parse_node.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/unit/test_json_parse_node.py b/tests/unit/test_json_parse_node.py index 7bec942..cf1e003 100644 --- a/tests/unit/test_json_parse_node.py +++ b/tests/unit/test_json_parse_node.py @@ -141,6 +141,25 @@ def test_get_anythin_does_not_convert_numeric_chars_to_datetime(): assert result == "1212" +def test_get_anythin_does_not_convert_any_length_numeric_chars_to_datetime(): + parse_node = JsonParseNode("1212") + result1 = parse_node.try_get_anything("1212") + parse_node_two = JsonParseNode("-PT15M") + result2 = parse_node_two.try_get_anything("-PT15M") + parse_node_three = JsonParseNode("20081008") + result3 = parse_node_three.try_get_anything("20081008") + parse_node_four = JsonParseNode("1011317") + result4 = parse_node_four.try_get_anything("1011317") + assert isinstance(result1, str) + assert result1 == "1212" + assert isinstance(result2, str) + assert result2 == "-PT15M" + assert isinstance(result3, str) + assert result3 == "20081008" + assert isinstance(result4, str) + assert result4 == "1011317" + + def test_get_anythin_does_convert_date_string_to_datetime(): parse_node = JsonParseNode("2023-10-05T14:48:00.000Z") result = parse_node.try_get_anything("2023-10-05T14:48:00.000Z") From 7683982134e981ff5b45027c8d37d148cd0de869 Mon Sep 17 00:00:00 2001 From: shemogumbe Date: Tue, 10 Sep 2024 13:03:49 +0300 Subject: [PATCH 4/4] update version and changelog --- CHANGELOG.md | 8 ++++++++ kiota_serialization_json/_version.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb6a78f..6186cbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.3.2] - 2024-09-10 + +### Added + +- Fixed numeric strings from being parsed as Datetime objects to being parsed as strings. +-Only parse to Datetime objects that conform to ISO 8601 format. + + ## [1.3.1] - 2024-08-23 diff --git a/kiota_serialization_json/_version.py b/kiota_serialization_json/_version.py index d045b44..b84f08f 100644 --- a/kiota_serialization_json/_version.py +++ b/kiota_serialization_json/_version.py @@ -1 +1 @@ -VERSION: str = '1.3.1' +VERSION: str = '1.3.2'