Skip to content

Commit 4d453de

Browse files
authored
fix(external-storage): correct the storage reference check (#313)
1 parent 0f7d257 commit 4d453de

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

external_storage/handler.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@
2222
from aiohttp import web
2323
from google.protobuf import json_format
2424
from temporalio.api.common.v1 import Payload, Payloads
25+
from temporalio.api.sdk.v1 import ExternalStorageReference
2526
from temporalio.converter import ExternalStorage, PayloadCodec
2627

28+
_REFERENCE_MESSAGE_TYPE = ExternalStorageReference.DESCRIPTOR.full_name.encode()
2729

28-
def _is_storage_reference(payload: Payload) -> bool:
29-
"""A payload is an external-storage reference iff it carries external_payloads metadata.
3030

31-
When the SDK offloads a payload to external storage it replaces the
32-
in-band bytes with a small protobuf "claim check" — the ``external_payloads``
33-
repeated field is the marker the SDK uses to recognize it on the way back.
31+
def _is_storage_reference(payload: Payload) -> bool:
32+
"""A payload is an external-storage reference iff its metadata identifies
33+
it as a serialized :class:`ExternalStorageReference` claim check.
3434
"""
35-
return len(payload.external_payloads) > 0
35+
return (
36+
payload.metadata.get("encoding") == b"json/protobuf"
37+
and payload.metadata.get("messageType") == _REFERENCE_MESSAGE_TYPE
38+
)
3639

3740

3841
def payload_routes(

0 commit comments

Comments
 (0)