Skip to content

Commit deab876

Browse files
committed
Improvements from code review
1 parent 0ecc96f commit deab876

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

temporalio/converter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ def __init__(self, *converters: EncodingPayloadConverter) -> None:
353353
converters: Payload converters to delegate to, in order.
354354
"""
355355
self._set_converters(*converters)
356+
self._any_converter_takes_context = any(
357+
isinstance(c, WithSerializationContext) for c in converters
358+
)
356359

357360
def _set_converters(self, *converters: EncodingPayloadConverter) -> None:
358361
self.converters = {c.encoding.encode(): c for c in converters}
@@ -433,11 +436,13 @@ def with_context(self, context: SerializationContext) -> Self:
433436

434437
def get_converters_with_context(
435438
self, context: SerializationContext
436-
) -> Optional[List[EncodingPayloadConverter]]:
439+
) -> Optional[list[EncodingPayloadConverter]]:
437440
"""Return converter instances with context set.
438441
439442
If no converter uses context, return None.
440443
"""
444+
if not self._any_converter_takes_context:
445+
return None
441446
converters: list[EncodingPayloadConverter] = []
442447
any_with_context = False
443448
for c in self.converters.values():

temporalio/worker/_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ async def _handle_activation(
288288
else:
289289
payload_codec = _CommandAwarePayloadCodec(
290290
workflow.instance,
291-
self._data_converter.payload_codec,
291+
context_free_payload_codec=self._data_converter.payload_codec,
292292
)
293293
await temporalio.bridge.worker.decode_activation(
294294
act,
@@ -363,7 +363,7 @@ async def _handle_activation(
363363
if self._data_converter.payload_codec and workflow:
364364
payload_codec = _CommandAwarePayloadCodec(
365365
workflow.instance,
366-
self._data_converter.payload_codec,
366+
context_free_payload_codec=self._data_converter.payload_codec,
367367
)
368368
try:
369369
await temporalio.bridge.worker.encode_completion(

0 commit comments

Comments
 (0)