Skip to content

Commit f96679b

Browse files
authored
Fix issue with codecs returning passed-in payloads (#526)
Fixes #525
1 parent bc8c5c2 commit f96679b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

temporalio/bridge/worker.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ async def _apply_to_payloads(
175175
if len(payloads) == 0:
176176
return
177177
new_payloads = await cb(payloads)
178+
if new_payloads is payloads:
179+
return
178180
del payloads[:]
179181
# TODO(cretz): Copy too expensive?
180182
payloads.extend(new_payloads)
@@ -189,9 +191,7 @@ async def _apply_to_payload(
189191
) -> None:
190192
"""Apply API payload callback to payload."""
191193
new_payload = (await cb([payload]))[0]
192-
payload.metadata.clear()
193-
payload.metadata.update(new_payload.metadata)
194-
payload.data = new_payload.data
194+
payload.CopyFrom(new_payload)
195195

196196

197197
async def _decode_payloads(

tests/worker/test_workflow.py

+18
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,24 @@ async def test_workflow_with_codec(client: Client, env: WorkflowEnvironment):
14851485
await test_workflow_update_handlers_happy(client, env)
14861486

14871487

1488+
class PassThroughCodec(PayloadCodec):
1489+
async def encode(self, payloads: Sequence[Payload]) -> List[Payload]:
1490+
return list(payloads)
1491+
1492+
async def decode(self, payloads: Sequence[Payload]) -> List[Payload]:
1493+
return list(payloads)
1494+
1495+
1496+
async def test_workflow_with_passthrough_codec(client: Client):
1497+
# Make client with this codec and run the activity test. This used to fail
1498+
# because there was a bug where the codec couldn't reuse the passed-in
1499+
# payloads.
1500+
config = client.config()
1501+
config["data_converter"] = DataConverter(payload_codec=PassThroughCodec())
1502+
client = Client(**config)
1503+
await test_workflow_simple_activity(client)
1504+
1505+
14881506
class CustomWorkflowRunner(WorkflowRunner):
14891507
def __init__(self) -> None:
14901508
super().__init__()

0 commit comments

Comments
 (0)