Skip to content

Commit 09584f8

Browse files
committed
AI fix for
uv run pytest 'tests/worker/test_workflow.py::test_workflow_activity_outbound_conversion_failure' uv run pytest 'tests/worker/test_workflow.py::test_exception_raising_converter_param'
1 parent 567d5c4 commit 09584f8

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

temporalio/converter.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,21 @@ def __init__(self) -> None:
435435
"""Create a default payload converter."""
436436
super().__init__(*DefaultPayloadConverter.default_encoding_payload_converters)
437437

438+
def with_context(self, context: SerializationContext) -> Self:
439+
"""Return a new instance with the given context, preserving the class type."""
440+
# Create a new instance of the same class (works for subclasses too)
441+
instance = self.__class__()
442+
# Update the converters with context
443+
instance.converters = {
444+
encoding: (
445+
converter.with_context(context)
446+
if isinstance(converter, WithSerializationContext)
447+
else converter
448+
)
449+
for encoding, converter in self.converters.items()
450+
}
451+
return instance
452+
438453

439454
class BinaryNullPayloadConverter(EncodingPayloadConverter):
440455
"""Converter for 'binary/null' payloads supporting None values."""

temporalio/worker/_workflow_instance.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,8 @@ def __init__(self, det: WorkflowInstanceDetails) -> None:
225225
self._workflow_input: Optional[ExecuteWorkflowInput] = None
226226
self._info = det.info
227227
self._context_free_payload_codec = det.data_converter.payload_codec
228-
self._context_free_payload_converter = (
229-
det.data_converter.payload_converter_class()
230-
)
231-
self._context_free_failure_converter = (
232-
det.data_converter.failure_converter_class()
233-
)
228+
self._context_free_payload_converter = det.data_converter.payload_converter
229+
self._context_free_failure_converter = det.data_converter.failure_converter
234230
self._payload_converter, self._failure_converter = (
235231
self._converters_with_context(
236232
temporalio.converter.WorkflowSerializationContext(

0 commit comments

Comments
 (0)