Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #334 from pjmagee/datetime-empty-string-serialisat…
Browse files Browse the repository at this point in the history
…ion-bug

fix: get_datetime_value fails to serialize empty string
  • Loading branch information
baywet authored Jul 26, 2024
2 parents 9f91b3b + acf513b commit db233a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.3.0] - 2024-07-26

### Added

- Support `dict[str, Any]` and `list[dict[str, Any]]` when writing additional data.

### Changed

- Fixed a bug where date time deserialization would fail because of empty strings.

## [1.2.0] - 2024-04-09

### Added
Expand Down
4 changes: 4 additions & 0 deletions kiota_serialization_json/json_parse_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def get_datetime_value(self) -> Optional[datetime]:
"""
if isinstance(self._json_node, datetime):
return self._json_node

if isinstance(self._json_node, str):
if len(self._json_node) < 10:
return None

datetime_obj = pendulum.parse(self._json_node, exact=True)
if isinstance(datetime_obj, pendulum.DateTime):
return datetime_obj
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_json_parse_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def test_get_uuid_value():
result = parse_node.get_uuid_value()
assert result == UUID("f58411c7-ae78-4d3c-bb0d-3f24d948de41")

@pytest.mark.parametrize("value", ["", " ", " ", "2022-01-0"])
def test_get_datetime_value_returns_none_with_invalid_str(value: str):
parse_node = JsonParseNode(value)
result = parse_node.get_datetime_value()
assert result is None

def test_get_datetime_value():
parse_node = JsonParseNode('2022-01-27T12:59:45.596117')
Expand Down

0 comments on commit db233a0

Please sign in to comment.