Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dapr/serializers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def __init__(self, *args, **kwargs):
def custom_scanstring(cls, s, end, strict=True):
(s, end) = json.decoder.scanstring(s, end, strict) # type: ignore
if cls.datetime_regex.match(s):
return (parser.parse(s), end)
# The regex only checks the prefix, so a string such as
# '2024-01-01 notes' reaches the parser; keep it as a string.
try:
return (parser.parse(s), end)
except (ValueError, OverflowError):
return (s, end)

duration = DAPR_DURATION_PARSER.match(s)
if duration is not None and duration.lastindex is not None:
Expand Down
8 changes: 8 additions & 0 deletions tests/serializers/test_default_json_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ def test_deserialize(self):
),
)

def test_deserialize_string_with_date_prefix(self):
serializer = DefaultJSONSerializer()
payload = b'{"note":"2024-01-01 meeting notes","file":"2024/01/01_backup.tar"}'

obj = serializer.deserialize(payload)
self.assertEqual(obj['note'], '2024-01-01 meeting notes')
self.assertEqual(obj['file'], '2024/01/01_backup.tar')


if __name__ == '__main__':
unittest.main()
Loading