Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 6 decimal places cloud event #19019

Merged
merged 2 commits into from
Jun 1, 2021
Merged
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
1 change: 1 addition & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bug Fixes

- Retry policies don't sleep after operations time out
- The `from_dict` methhod in the `CloudEvent` can now convert a datetime string to datetime object when microsecond exceeds the python limitation


## 1.14.0 (2021-05-13)
Expand Down
11 changes: 11 additions & 0 deletions sdk/core/azure-core/azure/core/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ def _convert_to_isoformat(date_time):
sign, offset = date_time[-6], date_time[-5:]
delta = int(sign + offset[:1]) * 60 + int(sign + offset[-2:])

check_decimal = timestamp.split('.')
if len(check_decimal) > 1:
decimal_str = ""
for digit in check_decimal[1]:
if digit.isdigit():
decimal_str += digit
else:
break
if len(decimal_str) > 6:
timestamp = timestamp.replace(decimal_str, decimal_str[0:6])
lmazuel marked this conversation as resolved.
Show resolved Hide resolved

if delta == 0:
tzinfo = TZ_UTC
else:
Expand Down
6 changes: 4 additions & 2 deletions sdk/core/azure-core/tests/test_messaging_cloud_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_cloud_storage_dict():
"storage_diagnostics":{"batchId":"b68529f3-68cd-4744-baa4-3c0498ec19f0"}
},
"type":"Microsoft.Storage.BlobCreated",
"time":"2021-02-18T20:18:10.53986Z",
"time":"2021-02-18T20:18:10.581147898Z",
"specversion":"1.0"
}

Expand All @@ -120,6 +120,7 @@ def test_cloud_storage_dict():
assert event.time.month == 2
assert event.time.day == 18
assert event.time.hour == 20
assert event.time.microsecond == 581147
assert event.__class__ == CloudEvent
assert "id" in cloud_storage_dict
assert "data" in cloud_storage_dict
Expand All @@ -131,7 +132,7 @@ def test_cloud_custom_dict_with_extensions():
"source":"https://egtest.dev/cloudcustomevent",
"data":{"team": "event grid squad"},
"type":"Azure.Sdk.Sample",
"time":"2021-02-18T20:18:10.53986+00:00",
"time":"2021-02-18T20:18:10.539861122+00:00",
"specversion":"1.0",
"ext1": "example",
"ext2": "example2"
Expand All @@ -142,6 +143,7 @@ def test_cloud_custom_dict_with_extensions():
assert event.time.month == 2
assert event.time.day == 18
assert event.time.hour == 20
assert event.time.microsecond == 539861
assert event.extensions == {"ext1": "example", "ext2": "example2"}

def test_cloud_custom_dict_blank_data():
Expand Down