Skip to content

Commit deb1751

Browse files
committed
allow empty operations list
1 parent 9084f7f commit deb1751

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/aws_durable_execution_sdk_python/execution.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,15 @@ def from_dict(input_dict: MutableMapping[str, Any]) -> InitialExecutionState:
5858
next_marker=input_dict.get("NextMarker", ""),
5959
)
6060

61-
def get_execution_operation(self) -> Operation:
61+
def get_execution_operation(self) -> Operation | None:
6262
if len(self.operations) < 1:
63+
# Due to payload size limitations we may have an empty operations list.
64+
# This will only happen when loading the initial page of results and is
65+
# expected behaviour. We don't fail, but instead return None
66+
# as the execution operation does not exist
6367
msg: str = "No durable operations found in initial execution state."
64-
raise DurableExecutionsError(msg)
68+
logger.debug(msg)
69+
return None
6570

6671
candidate = self.operations[0]
6772
if candidate.operation_type is not OperationType.EXECUTION:
@@ -71,11 +76,15 @@ def get_execution_operation(self) -> Operation:
7176
return candidate
7277

7378
def get_input_payload(self) -> str | None:
74-
# TODO: are these None checks necessary? i.e will there always be execution_details with input_payload
75-
if execution_details := self.get_execution_operation().execution_details:
76-
return execution_details.input_payload
77-
78-
return None
79+
# It is possible that backend will not provide an execution operation
80+
# for the initial page of results.
81+
if not (operations := self.get_execution_operation()):
82+
return None
83+
if not (execution_details := operations.execution_details):
84+
return None
85+
if not (input_payload := execution_details.input_payload):
86+
return None
87+
return input_payload
7988

8089
def to_dict(self) -> MutableMapping[str, Any]:
8190
return {

tests/execution_test.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,16 @@ def test_handler(event: Any, context: DurableContext) -> dict:
788788

789789

790790
def test_initial_execution_state_get_execution_operation_no_operations():
791-
"""Test get_execution_operation raises error when no operations exist."""
791+
"""Test get_execution_operation logs debug and returns None when no operations exist."""
792792
state = InitialExecutionState(operations=[], next_marker="")
793793

794-
with pytest.raises(
795-
Exception, match="No durable operations found in initial execution state"
796-
):
797-
state.get_execution_operation()
794+
with patch("aws_durable_execution_sdk_python.execution.logger") as mock_logger:
795+
result = state.get_execution_operation()
796+
797+
assert result is None
798+
mock_logger.debug.assert_called_once_with(
799+
"No durable operations found in initial execution state."
800+
)
798801

799802

800803
def test_initial_execution_state_get_execution_operation_wrong_type():

0 commit comments

Comments
 (0)