From 84d51ce27fb3a848f4436bccaf99959f1065bcfa Mon Sep 17 00:00:00 2001 From: walmy Date: Tue, 8 Aug 2023 09:49:25 -0700 Subject: [PATCH] Add ignore_unknown_fields as an argument to JSONProtoPayloadConverter --- temporalio/converter.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/temporalio/converter.py b/temporalio/converter.py index 19546ff9..497ceb64 100644 --- a/temporalio/converter.py +++ b/temporalio/converter.py @@ -388,6 +388,16 @@ def from_payload( class JSONProtoPayloadConverter(EncodingPayloadConverter): """Converter for 'json/protobuf' payloads supporting protobuf Message values.""" + def __init__(self, ignore_unknown_fields: bool = False): + """Initialize a JSON proto converter. + + Args: + ignore_unknown_fields: Determines whether converter should error if + unknown fields are detected + """ + super().__init__() + self._ignore_unknown_fields = ignore_unknown_fields + @property def encoding(self) -> str: """See base class.""" @@ -424,7 +434,11 @@ def from_payload( message_type = payload.metadata.get("messageType", b"").decode() try: value = _sym_db.GetSymbol(message_type)() - return google.protobuf.json_format.Parse(payload.data, value) + return google.protobuf.json_format.Parse( + payload.data, + value, + ignore_unknown_fields=self._ignore_unknown_fields, + ) except KeyError as err: raise RuntimeError(f"Unknown Protobuf type {message_type}") from err except google.protobuf.json_format.ParseError as err: