Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,14 @@ def to_dict(self) -> MutableMapping[str, Any]:
"InputPayload": self.execution_details.input_payload
}
if self.context_details:
result["ContextDetails"] = {"Result": self.context_details.result}
context_dict: MutableMapping[str, Any] = {
"Result": self.context_details.result,
}
if self.context_details.error:
context_dict["Error"] = self.context_details.error.to_dict()
if self.context_details.replay_children:
context_dict["ReplayChildren"] = self.context_details.replay_children
result["ContextDetails"] = context_dict
if self.step_details:
step_dict: MutableMapping[str, Any] = {"Attempt": self.step_details.attempt}
if self.step_details.next_attempt_timestamp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2843,3 +2843,42 @@ def test_timestamp_converter_millisecond_boundaries():


# endregion


def test_operation_to_dict_serializes_context_error_and_replay_children():
"""Operation.to_dict includes Error and ReplayChildren in ContextDetails."""
op = Operation(
operation_id="ctx-1",
operation_type=OperationType.CONTEXT,
status=OperationStatus.FAILED,
context_details=ContextDetails(
replay_children=True,
result=None,
error=ErrorObject(
message="boom",
type="ChildContextError",
data=None,
stack_trace=None,
),
),
)

context = op.to_dict()["ContextDetails"]

assert context["Error"]["ErrorType"] == "ChildContextError"
assert context["Error"]["ErrorMessage"] == "boom"
assert context["ReplayChildren"] is True


def test_operation_to_dict_omits_absent_context_error_and_replay_children():
"""Operation.to_dict omits Error and ReplayChildren when they are not set."""
op = Operation(
operation_id="ctx-2",
operation_type=OperationType.CONTEXT,
status=OperationStatus.SUCCEEDED,
context_details=ContextDetails(result='"hello"'),
)

context = op.to_dict()["ContextDetails"]

assert context == {"Result": '"hello"'}
Loading