You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using the Field annotation on an arg to be converted into a JSON field, nullable types don't work as expected. Using Optional directly throws an error, but you can work around this by using the x | None syntax instead. However, this is causing the request body to include unintended nulls.
I have created this class that takes the idea from the Query function annotation.
from uplink import Field
class CustomField(Field):
def __init__(self, name=None, type=None, encode_none=None):
super(CustomField, self).__init__(name, type)
self._encode_none = encode_none
def _modify_request(self, request_builder, value):
if value is None:
if self._encode_none is None:
return
value = self._encode_none
super(CustomField, self)._modify_request(request_builder, value)
But still i don't like this approach, what if you want to pass something in the body that has None value?
Describe the bug
When using the Field annotation on an arg to be converted into a JSON field, nullable types don't work as expected. Using Optional directly throws an error, but you can work around this by using the
x | None
syntax instead. However, this is causing the request body to include unintended nulls.To Reproduce
Result:
TypeError: issubclass() arg 1 must be a class
Result
It would be nice if this had the same behavior as Query params.
The text was updated successfully, but these errors were encountered: