-
Notifications
You must be signed in to change notification settings - Fork 3
IWF-808 use Unset object for empty data output
#106
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
Conversation
| 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", | ||
| ) |
There was a problem hiding this comment.
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.
iwf/object_encoder.py
Outdated
| 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()) |
There was a problem hiding this comment.
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
| def encoding(self) -> Union[str, Unset]: | ||
| """See base class.""" | ||
| return "binary/null" | ||
| return UNSET |
There was a problem hiding this comment.
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.
* IWF-808 use `Unset` object for empty data output --------- Co-authored-by: Nathan Givens <ngivens@indeed.com>
No description provided.