Skip to content

Conversation

@N-give
Copy link
Contributor

@N-give N-give commented Apr 28, 2025

No description provided.

Comment on lines +172 to 181
payload: Union[EncodedObject, Unset] = Unset()
is_encoded = False
for converter in self.converters.values():
payload = converter.to_payload(value)
if payload is not None:
is_encoded, payload = converter.to_payload(value)
if is_encoded:
break
if payload is None:
if not is_encoded:
raise RuntimeError(
f"Value of type {type(value)} has no known converter",
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we were overloading None to also mean not yet encoded, but that shouldn't always be the case. If no data comes in, we can return no data.

Comment on lines 233 to 241
def encoding(self) -> Union[str, Unset]:
"""See base class."""
return "binary/null"
return UNSET

def to_payload(self, value: Any) -> Optional[EncodedObject]:
def to_payload(self, value: Any) -> tuple[bool, Union[EncodedObject, Unset]]:
"""See base class."""
if value is None:
return EncodedObject(
encoding=self.encoding,
)
return None
return (True, Unset())
return (False, Unset())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get the response to have data=null like the java-sdk, this needed to return Unset instead of an EncodedObject with an encoding and a empty data. The to_dict method generated for the response object will include anything that isn't Unset

Comment on lines +233 to +235
def encoding(self) -> Union[str, Unset]:
"""See base class."""
return "binary/null"
return UNSET
Copy link
Contributor Author

@N-give N-give Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CompositePayloadConverter stores all of the converters in a dict by their encoding, but when the server sends empty data, the encoding field of the EncodedObject will be UNSET, so for this to properly match, its encoding needs to also be UNSET.

@N-give N-give changed the base branch from main to jira/code-freeze/IWF-802 April 29, 2025 20:59
@N-give N-give merged commit 29f5c33 into jira/code-freeze/IWF-802 Apr 29, 2025
2 checks passed
N-give added a commit that referenced this pull request May 6, 2025
* IWF-808 use `Unset` object for empty data output

---------

Co-authored-by: Nathan Givens <ngivens@indeed.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants