Skip to content

Commit a2a4cc2

Browse files
authored
fix: StepDetails should deserialize unix timestamp to datetime (#57)
1 parent 640d4e6 commit a2a4cc2

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/aws_durable_execution_sdk_python/lambda_service.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ def from_dict(cls, data: MutableMapping[str, Any]) -> StepDetails:
158158
error_raw = data.get("Error")
159159
return cls(
160160
attempt=data.get("Attempt", 0),
161-
next_attempt_timestamp=data.get(
162-
"NextAttemptTimestamp"
163-
), # TODO: how is this serialized? Unix or ISO 8601?
161+
next_attempt_timestamp=data.get("NextAttemptTimestamp"),
164162
result=data.get("Result"),
165163
error=ErrorObject.from_dict(error_raw) if error_raw else None,
166164
)

tests/lambda_service_test.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,17 @@ def test_step_details_from_dict():
230230
error_data = {"ErrorMessage": "Step error"}
231231
data = {
232232
"Attempt": 2,
233-
"NextAttemptTimestamp": "2023-01-01T00:00:00Z",
233+
"NextAttemptTimestamp": datetime.datetime(
234+
2023, 1, 1, 0, 0, 0, tzinfo=datetime.UTC
235+
),
234236
"Result": "step_result",
235237
"Error": error_data,
236238
}
237239
details = StepDetails.from_dict(data)
238240
assert details.attempt == 2
239-
assert details.next_attempt_timestamp == "2023-01-01T00:00:00Z"
241+
assert details.next_attempt_timestamp == datetime.datetime(
242+
2023, 1, 1, 0, 0, 0, tzinfo=datetime.UTC
243+
)
240244
assert details.result == "step_result"
241245
assert details.error.message == "Step error"
242246

@@ -246,13 +250,17 @@ def test_step_details_all_fields():
246250
error_data = {"ErrorMessage": "Step failed", "ErrorType": "StepError"}
247251
data = {
248252
"Attempt": 3,
249-
"NextAttemptTimestamp": "2023-01-01T12:00:00Z",
253+
"NextAttemptTimestamp": datetime.datetime(
254+
2023, 1, 1, 12, 0, 0, tzinfo=datetime.UTC
255+
),
250256
"Result": "step_success",
251257
"Error": error_data,
252258
}
253259
details = StepDetails.from_dict(data)
254260
assert details.attempt == 3
255-
assert details.next_attempt_timestamp == "2023-01-01T12:00:00Z"
261+
assert details.next_attempt_timestamp == datetime.datetime(
262+
2023, 1, 1, 12, 0, 0, tzinfo=datetime.UTC
263+
)
256264
assert details.result == "step_success"
257265
assert details.error.message == "Step failed"
258266
assert details.error.type == "StepError"

0 commit comments

Comments
 (0)