Skip to content

Commit 9c80eb7

Browse files
committed
Make DataConverter implement the interface
1 parent 82de81a commit 9c80eb7

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

temporalio/client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ def __init__(
16091609

16101610
@functools.cached_property
16111611
def _data_converter(self) -> temporalio.converter.DataConverter:
1612-
return self._client.data_converter._with_context(
1612+
return self._client.data_converter.with_context(
16131613
temporalio.converter.WorkflowSerializationContext(
16141614
namespace=self._client.namespace, workflow_id=self._id
16151615
)
@@ -2865,7 +2865,7 @@ def with_context(self, context: SerializationContext) -> AsyncActivityHandle:
28652865
return AsyncActivityHandle(
28662866
self._client,
28672867
self._id_or_token,
2868-
self._client.data_converter._with_context(context),
2868+
self._client.data_converter.with_context(context),
28692869
)
28702870

28712871

@@ -3234,7 +3234,7 @@ async def fetch_next_page(self, *, page_size: Optional[int] = None) -> None:
32343234
def get_data_converter(workflow_id: str) -> temporalio.converter.DataConverter:
32353235
if workflow_id not in data_converter_cache:
32363236
data_converter_cache[workflow_id] = (
3237-
self._client.data_converter._with_context(
3237+
self._client.data_converter.with_context(
32383238
WorkflowSerializationContext(
32393239
namespace=self._client.namespace,
32403240
workflow_id=workflow_id,
@@ -4204,7 +4204,7 @@ async def _to_proto(
42044204
priority: Optional[temporalio.api.common.v1.Priority] = None
42054205
if self.priority:
42064206
priority = self.priority._to_proto()
4207-
data_converter = client.data_converter._with_context(
4207+
data_converter = client.data_converter.with_context(
42084208
WorkflowSerializationContext(
42094209
namespace=client.namespace,
42104210
workflow_id=self.id,
@@ -5063,7 +5063,7 @@ def __init__(
50635063

50645064
@functools.cached_property
50655065
def _data_converter(self) -> temporalio.converter.DataConverter:
5066-
return self._client.data_converter._with_context(
5066+
return self._client.data_converter.with_context(
50675067
WorkflowSerializationContext(
50685068
namespace=self._client.namespace,
50695069
workflow_id=self.workflow_id,
@@ -5977,7 +5977,7 @@ async def _build_signal_with_start_workflow_execution_request(
59775977
self, input: StartWorkflowInput
59785978
) -> temporalio.api.workflowservice.v1.SignalWithStartWorkflowExecutionRequest:
59795979
assert input.start_signal
5980-
data_converter = self._client.data_converter._with_context(
5980+
data_converter = self._client.data_converter.with_context(
59815981
WorkflowSerializationContext(
59825982
namespace=self._client.namespace,
59835983
workflow_id=input.id,
@@ -6008,7 +6008,7 @@ async def _populate_start_workflow_execution_request(
60086008
],
60096009
input: Union[StartWorkflowInput, UpdateWithStartStartWorkflowInput],
60106010
) -> None:
6011-
data_converter = self._client.data_converter._with_context(
6011+
data_converter = self._client.data_converter.with_context(
60126012
WorkflowSerializationContext(
60136013
namespace=self._client.namespace,
60146014
workflow_id=input.id,
@@ -6095,7 +6095,7 @@ async def describe_workflow(
60956095
metadata=input.rpc_metadata,
60966096
timeout=input.rpc_timeout,
60976097
),
6098-
self._client.data_converter._with_context(
6098+
self._client.data_converter.with_context(
60996099
WorkflowSerializationContext(
61006100
namespace=self._client.namespace,
61016101
workflow_id=input.id,
@@ -6129,7 +6129,7 @@ async def count_workflows(
61296129
)
61306130

61316131
async def query_workflow(self, input: QueryWorkflowInput) -> Any:
6132-
data_converter = self._client.data_converter._with_context(
6132+
data_converter = self._client.data_converter.with_context(
61336133
WorkflowSerializationContext(
61346134
namespace=self._client.namespace,
61356135
workflow_id=input.id,
@@ -6182,7 +6182,7 @@ async def query_workflow(self, input: QueryWorkflowInput) -> Any:
61826182
return results[0]
61836183

61846184
async def signal_workflow(self, input: SignalWorkflowInput) -> None:
6185-
data_converter = self._client.data_converter._with_context(
6185+
data_converter = self._client.data_converter.with_context(
61866186
WorkflowSerializationContext(
61876187
namespace=self._client.namespace,
61886188
workflow_id=input.id,
@@ -6207,7 +6207,7 @@ async def signal_workflow(self, input: SignalWorkflowInput) -> None:
62076207
)
62086208

62096209
async def terminate_workflow(self, input: TerminateWorkflowInput) -> None:
6210-
data_converter = self._client.data_converter._with_context(
6210+
data_converter = self._client.data_converter.with_context(
62116211
WorkflowSerializationContext(
62126212
namespace=self._client.namespace,
62136213
workflow_id=input.id,
@@ -6281,7 +6281,7 @@ async def _build_update_workflow_execution_request(
62816281
input: Union[StartWorkflowUpdateInput, UpdateWithStartUpdateWorkflowInput],
62826282
workflow_id: str,
62836283
) -> temporalio.api.workflowservice.v1.UpdateWorkflowExecutionRequest:
6284-
data_converter = self._client.data_converter._with_context(
6284+
data_converter = self._client.data_converter.with_context(
62856285
WorkflowSerializationContext(
62866286
namespace=self._client.namespace,
62876287
workflow_id=workflow_id,

temporalio/converter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ def __init__(self) -> None:
12331233

12341234

12351235
@dataclass(frozen=True)
1236-
class DataConverter:
1236+
class DataConverter(WithSerializationContext):
12371237
"""Data converter for converting and encoding payloads to/from Python values.
12381238
12391239
This combines :py:class:`PayloadConverter` which converts values with
@@ -1337,7 +1337,8 @@ async def decode_failure(
13371337
await self.payload_codec.decode_failure(failure)
13381338
return self.failure_converter.from_failure(failure, self.payload_converter)
13391339

1340-
def _with_context(self, context: SerializationContext) -> Self:
1340+
def with_context(self, context: SerializationContext) -> Self:
1341+
"""Return an instance with context set on the component converters."""
13411342
payload_converter = self.payload_converter
13421343
payload_codec = self.payload_codec
13431344
failure_converter = self.failure_converter

temporalio/worker/_activity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ async def _heartbeat_async(
262262
activity_task_queue=self._task_queue,
263263
is_local=activity.info.is_local,
264264
)
265-
data_converter = data_converter._with_context(context)
265+
data_converter = data_converter.with_context(context)
266266

267267
# Perform the heartbeat
268268
try:
@@ -314,7 +314,7 @@ async def _handle_start_activity_task(
314314
activity_task_queue=self._task_queue,
315315
is_local=start.is_local,
316316
)
317-
data_converter = self._data_converter._with_context(context)
317+
data_converter = self._data_converter.with_context(context)
318318
try:
319319
result = await self._execute_activity(
320320
start, running_activity, task_token, data_converter

temporalio/worker/_workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ async def _handle_activation(
275275
"Cache already exists for activation with initialize job"
276276
)
277277

278-
data_converter = self._data_converter._with_context(
278+
data_converter = self._data_converter.with_context(
279279
temporalio.converter.WorkflowSerializationContext(
280280
namespace=self._namespace,
281281
workflow_id=workflow_id,

0 commit comments

Comments
 (0)