Skip to content

feat: Batch Result serialization#114

Merged
4 commits merged intomainfrom
serialize-batch-result
Nov 7, 2025
Merged

feat: Batch Result serialization#114
4 commits merged intomainfrom
serialize-batch-result

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Nov 2, 2025

  • Adds serialization for batch result in the serdes module.
  • Splits the concurrency module into models and implementation.

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ghost ghost force-pushed the serialize-batch-result branch from d30b11b to 4b87d75 Compare November 2, 2025 20:56
@yaythomas
Copy link
Copy Markdown
Contributor

superseded by #115

@yaythomas yaythomas closed this Nov 3, 2025
@ghost ghost reopened this Nov 6, 2025
@ghost ghost force-pushed the serialize-batch-result branch from 4b87d75 to 13998d2 Compare November 6, 2025 19:08
- Adds serialization for batch result in the serdes module.

Unfortunately we need to do an adhoc import as we are dealing
with cyclical dependencies.
@ghost ghost force-pushed the serialize-batch-result branch from 13998d2 to bbed24a Compare November 6, 2025 19:12
Changes:
 - add tests to verify BatchResult is serialized
 - add tests to verify BatchResult actually serializes by default
 - add tests to verify we pass custom serdes and that is used to
   serialize BatchResult
Comment on lines +973 to +981
with patch.object(
DurableContext, "_create_step_id_for_logical_step", create_id
):
context = DurableContext(state=mock_state)
result = context.map(["a", "b"], lambda ctx, item, idx, items: item)

assert len(mock_serdes_serialize.call_args_list) == 3
parent_call = mock_serdes_serialize.call_args_list[2]
assert parent_call[1]["value"] is result
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify that we have called serialize with the same BatchResult that we are actually returning.

Comment on lines +1035 to +1041
assert isinstance(result, BatchResult)
assert len(mock_serialize.call_args_list) == 3
parent_call = mock_serialize.call_args_list[2]
assert parent_call[1]["serdes"] is None
assert isinstance(parent_call[1]["value"], BatchResult)
assert parent_call[1]["value"] is result

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify that we have called with the same BatchResult we return, and default serializer actually serializes.

Comment thread tests/operation/map_test.py Outdated
Comment on lines +991 to +994
with patch(
"aws_durable_execution_sdk_python.serdes.serialize", wraps=serialize
) as mock_serialize:
importlib.reload(child_module)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wrap to ensure we are actually calling serialize

Comment on lines +1099 to +1104
assert isinstance(result, BatchResult)
assert len(mock_serialize.call_args_list) == 3
parent_call = mock_serialize.call_args_list[2]
assert parent_call[1]["serdes"] is custom_serdes
assert isinstance(parent_call[1]["value"], BatchResult)
assert parent_call[1]["value"] is result
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure custom serdes is actually called with same returned batch result, and we call serialize.

@ghost ghost marked this pull request as ready for review November 6, 2025 22:04
@ghost ghost requested review from wangyb-A and yaythomas as code owners November 6, 2025 22:04
Copy link
Copy Markdown
Contributor

@wangyb-A wangyb-A left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

concurrency/__init __ .py exists cuz Ruff was complaining :D

case list() | tuple() | dict():
return self.container_codec.encode(obj)
case _:
if isinstance(obj, BatchResult):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why here too? (see line 248)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooopsies, remnant from cyclical dependency

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah will fix.

Comment thread src/aws_durable_execution_sdk_python/concurrency/executor.py
@ghost ghost merged commit 4eecf0e into main Nov 7, 2025
8 of 9 checks passed
@wangyb-A wangyb-A deleted the serialize-batch-result branch December 9, 2025 22:29
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants