Skip to content

Commit

Permalink
Add ignore_unknown_fields as an argument to JSONProtoPayloadConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
walmy authored and walmy committed Aug 8, 2023
1 parent 24fea4c commit 84d51ce
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion temporalio/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -424,7 +434,11 @@ def from_payload(
message_type = payload.metadata.get("messageType", b"<unknown>").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:
Expand Down

0 comments on commit 84d51ce

Please sign in to comment.