-
Notifications
You must be signed in to change notification settings - Fork 62
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
Uplink crashes on python3.9 when trying to serialize pydantic model #234
Comments
This seems to be related to pydantic/pydantic#1298 edit: still occurs with pydantic==1.8.2 and uplink==0.9.4 |
I used this workaround to patch this in my testing suite: @pytest.fixture(autouse=True)
def uplink_patch(monkeypatch, logger):
def is_subclass_patch(cls, class_info):
with suppress(TypeError):
return inspect.isclass(cls) and issubclass(cls, class_info)
logger.debug('Due to uplink issue https://github.com/prkumar/uplink/issues/234 we need to monkeypatch uplink')
monkeypatch.setattr('uplink.utils.is_subclass', is_subclass_patch) |
@prkumar this seems to be a little more complicated than I initially investigated, as a self contained example seems to work just fine: import uplink
from pydantic import BaseModel
class HTTPBinData(BaseModel):
foo: dict
class HTTPBinClient(uplink.Consumer):
@uplink.returns.json(key=('json', 'data'))
@uplink.json
@uplink.post('/anything')
def get_json(self, data: uplink.Field) -> list[HTTPBinData]:
pass
c = HTTPBinClient(base_url='https://httpbin.org')
print(c.get_json(data=[{'foo': {}}])) I believe this has something to do with pre-registered converters. I'll continue to investigate |
Is there any progress on this? Using:
I have a similar problem:
Then:
Looks like Uplink does not recognise the data being a list and passes it directly to pydantic, which crashes because it expects a dictionary as the root. For clarity here is example data:
|
@bal-stan, I think you can fix your problem with the returns.json decorator:
|
Describe the bug
Uplink crashes on python3.9 when trying to serialize model
To Reproduce
This is the uplink class and method:
This is the crash:
Expected behavior
Not to crash
Additional context
This results from an apparant change in
issubclass()
in python 3.9.I debugged this in 3.6 (where it's working):
And 3.9:
Apparently
issubclass()
does not consider this to be a class in python 3.9, haven't dug deep in its changelog to try and figure out whyThe text was updated successfully, but these errors were encountered: