Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow JSONProtoPayloadConverter to accept ignore_unknown_fields as an optional argument #365

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading