Skip to content

Commit 90e4287

Browse files
committed
chore: DurableContext not inherit LambdaContext
DurableContext now has a lambda_context property via composition, rather than inheriting the LambdaContext.
1 parent c8dd3c8 commit 90e4287

6 files changed

Lines changed: 24 additions & 714 deletions

File tree

src/aws_durable_execution_sdk_python/context.py

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
ValidationError,
2121
)
2222
from aws_durable_execution_sdk_python.identifier import OperationIdentifier
23-
from aws_durable_execution_sdk_python.lambda_context import (
24-
LambdaContext,
25-
make_dict_from_obj,
26-
)
2723
from aws_durable_execution_sdk_python.lambda_service import OperationSubType
2824
from aws_durable_execution_sdk_python.logger import Logger, LogInfo
2925
from aws_durable_execution_sdk_python.operation.callback import (
@@ -149,32 +145,16 @@ def result(self) -> T | None:
149145
raise FatalError(msg)
150146

151147

152-
# It really would be great NOT to have to inherit from the LambdaContext.
153-
# lot of noise here that we're not actually using. Alternative is to include
154-
# via composition rather than inheritance
155-
class DurableContext(LambdaContext, DurableContextProtocol):
148+
class DurableContext(DurableContextProtocol):
156149
def __init__(
157150
self,
158151
state: ExecutionState,
152+
lambda_context: Any | None = None,
159153
parent_id: str | None = None,
160154
logger: Logger | None = None,
161-
# LambdaContext members follow
162-
invoke_id=None,
163-
client_context=None,
164-
cognito_identity=None,
165-
epoch_deadline_time_in_ms=0,
166-
invoked_function_arn=None,
167-
tenant_id=None,
168155
) -> None:
169-
super().__init__(
170-
invoke_id=invoke_id,
171-
client_context=client_context,
172-
cognito_identity=cognito_identity,
173-
epoch_deadline_time_in_ms=epoch_deadline_time_in_ms,
174-
invoked_function_arn=invoked_function_arn,
175-
tenant_id=tenant_id,
176-
)
177156
self.state: ExecutionState = state
157+
self.lambda_context = lambda_context
178158
self._parent_id: str | None = parent_id
179159
self._step_counter: OrderedCounter = OrderedCounter()
180160

@@ -195,37 +175,26 @@ def __init__(
195175
@staticmethod
196176
def from_lambda_context(
197177
state: ExecutionState,
198-
lambda_context: LambdaContext,
178+
lambda_context: Any,
199179
):
200180
return DurableContext(
201181
state=state,
182+
lambda_context=lambda_context,
202183
parent_id=None,
203-
invoke_id=lambda_context.aws_request_id,
204-
client_context=make_dict_from_obj(lambda_context.client_context),
205-
cognito_identity=make_dict_from_obj(lambda_context.identity),
206-
# not great to have to use the private-ish accessor here, but for the moment not messing with LambdaContext signature
207-
epoch_deadline_time_in_ms=lambda_context._epoch_deadline_time_in_ms, # noqa: SLF001
208-
invoked_function_arn=lambda_context.invoked_function_arn,
209-
tenant_id=lambda_context.tenant_id,
210184
)
211185

212186
def create_child_context(self, parent_id: str) -> DurableContext:
213187
"""Create a child context from the given parent."""
214188
logger.debug("Creating child context for parent %s", parent_id)
215189
return DurableContext(
216190
state=self.state,
191+
lambda_context=self.lambda_context,
217192
parent_id=parent_id,
218193
logger=self.logger.with_log_info(
219194
LogInfo(
220195
execution_arn=self.state.durable_execution_arn, parent_id=parent_id
221196
)
222197
),
223-
invoke_id=self.aws_request_id,
224-
client_context=make_dict_from_obj(self.client_context),
225-
cognito_identity=make_dict_from_obj(self.identity),
226-
epoch_deadline_time_in_ms=self._epoch_deadline_time_in_ms,
227-
invoked_function_arn=self.invoked_function_arn,
228-
tenant_id=self.tenant_id,
229198
)
230199

231200
# endregion factories

src/aws_durable_execution_sdk_python/execution.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
if TYPE_CHECKING:
2626
from collections.abc import Callable, MutableMapping
2727

28-
from aws_durable_execution_sdk_python.lambda_context import LambdaContext
2928

3029
logger = logging.getLogger(__name__)
3130

@@ -188,10 +187,10 @@ def create_succeeded(cls, result: str) -> DurableExecutionInvocationOutput:
188187

189188
def durable_handler(
190189
func: Callable[[Any, DurableContext], Any],
191-
) -> Callable[[Any, LambdaContext], Any]:
190+
) -> Callable[[Any, Any], Any]:
192191
logger.debug("Starting durable execution handler...")
193192

194-
def wrapper(event: Any, context: LambdaContext) -> MutableMapping[str, Any]:
193+
def wrapper(event: Any, context: Any) -> MutableMapping[str, Any]:
195194
invocation_input: DurableExecutionInvocationInput
196195
service_client: DurableServiceClient
197196

src/aws_durable_execution_sdk_python/lambda_context.py

Lines changed: 0 additions & 188 deletions
This file was deleted.

tests/e2e/execution_int_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
InvocationStatus,
1515
durable_handler,
1616
)
17-
from aws_durable_execution_sdk_python.lambda_context import LambdaContext
17+
18+
# LambdaContext no longer needed - using duck typing
1819
from aws_durable_execution_sdk_python.lambda_service import (
1920
CheckpointOutput,
2021
CheckpointUpdatedExecutionState,
@@ -102,7 +103,7 @@ def mock_checkpoint(
102103
}
103104

104105
# Create mock lambda context
105-
lambda_context = Mock(spec=LambdaContext)
106+
lambda_context = Mock()
106107
lambda_context.aws_request_id = "test-request-id"
107108
lambda_context.client_context = None
108109
lambda_context.identity = None
@@ -185,7 +186,7 @@ def mock_checkpoint(
185186
}
186187

187188
# Create mock lambda context
188-
lambda_context = Mock(spec=LambdaContext)
189+
lambda_context = Mock()
189190
lambda_context.aws_request_id = "test-request-id"
190191
lambda_context.client_context = None
191192
lambda_context.identity = None
@@ -277,7 +278,7 @@ def mock_checkpoint(
277278
}
278279

279280
# Create mock lambda context
280-
lambda_context = Mock(spec=LambdaContext)
281+
lambda_context = Mock()
281282
lambda_context.aws_request_id = "test-request-id"
282283
lambda_context.client_context = None
283284
lambda_context.identity = None
@@ -368,7 +369,7 @@ def mock_checkpoint(
368369
}
369370

370371
# Create mock lambda context
371-
lambda_context = Mock(spec=LambdaContext)
372+
lambda_context = Mock()
372373
lambda_context.aws_request_id = "test-request-id"
373374
lambda_context.client_context = None
374375
lambda_context.identity = None

0 commit comments

Comments
 (0)