Skip to content

Commit fe6ba86

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

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

temporalio/converter.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,18 +417,23 @@ 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, any_with_context = [], False
425+
for c in self.converters.values():
426+
if isinstance(c, WithSerializationContext):
427+
converters.append(c.with_context(context))
428+
any_with_context = True
429+
else:
430+
converters.append(c)
431+
432+
if not any_with_context:
433+
return self
434+
421435
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-
)
436+
new_instance._set_converters(*converters)
432437
return new_instance
433438

434439

0 commit comments

Comments
 (0)