Skip to content

Commit 2e6698c

Browse files
committed
Return self if no changes
1 parent d9ed32e commit 2e6698c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

temporalio/converter.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,18 +417,24 @@ def from_payloads(
417417
return values
418418

419419
def with_context(self, context: SerializationContext) -> Self:
420-
"""Return a new instance with context set on the component converters"""
420+
"""Return a new instance with context set on the component converters.
421+
422+
If none of the component converters support with_context, return self.
423+
"""
424+
converters: list[EncodingPayloadConverter] = []
425+
any_with_context = False
426+
for c in self.converters.values():
427+
if isinstance(c, WithSerializationContext):
428+
converters.append(c.with_context(context))
429+
any_with_context = True
430+
else:
431+
converters.append(c)
432+
433+
if not any_with_context:
434+
return self
435+
421436
new_instance = type(self)()
422-
new_instance._set_converters(
423-
*(
424-
(
425-
c.with_context(context)
426-
if isinstance(c, WithSerializationContext)
427-
else c
428-
)
429-
for c in self.converters.values()
430-
)
431-
)
437+
new_instance._set_converters(*converters)
432438
return new_instance
433439

434440

0 commit comments

Comments
 (0)