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

Pydantic v2 is not supported #297

Open
djbios opened this issue Jul 19, 2023 · 1 comment · May be fixed by #298 or #304
Open

Pydantic v2 is not supported #297

djbios opened this issue Jul 19, 2023 · 1 comment · May be fixed by #298 or #304

Comments

@djbios
Copy link

djbios commented Jul 19, 2023

Describe the bug
Probably, current version of uplink is not supporting pydantic v2

To Reproduce

from uplink import Body, Consumer, post
from pydantic import BaseModel, AnyHttpUrl  # v2.0.3


class A(BaseModel):
    url: AnyHttpUrl


class C(Consumer):
    @post('http://localhost')
    def test(self, a: Body(type=A)):
        ...


a = A(url='http://localhost')
C().test(a=a)

gives

Traceback (most recent call last):
  File "/home/djbios/.config/JetBrains/PyCharm2022.2/scratches/scratch_31.py", line 16, in <module>
    C().test(a=a)
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/builder.py", line 100, in __call__
    self._request_definition.define_request(request_builder, args, kwargs)
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/commands.py", line 284, in define_request
    self._argument_handler.handle_call(
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/arguments.py", line 154, in handle_call
    self.handle_call_args(request_builder, call_args)
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/arguments.py", line 159, in handle_call_args
    annotation.modify_request(request_builder, call_args[name])
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/arguments.py", line 183, in modify_request
    converted_value = converter(value) if converter else value
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/converters/interfaces.py", line 6, in __call__
    return self.convert(*args, **kwargs)
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/converters/pydantic_.py", line 34, in convert
    return _encode_pydantic(value)
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/converters/pydantic_.py", line 25, in _encode_pydantic
    return _encode_pydantic(pydantic_encoder(obj))
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/converters/pydantic_.py", line 20, in _encode_pydantic
    return {_encode_pydantic(k): _encode_pydantic(v) for k, v in obj.items()}
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/converters/pydantic_.py", line 20, in <dictcomp>
    return {_encode_pydantic(k): _encode_pydantic(v) for k, v in obj.items()}
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/uplink/converters/pydantic_.py", line 25, in _encode_pydantic
    return _encode_pydantic(pydantic_encoder(obj))
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/typing_extensions.py", line 2562, in wrapper
    return __arg(*args, **kwargs)
  File "/home/djbios/.pyenv/versions/3.10.8/lib/python3.10/site-packages/pydantic/deprecated/json.py", line 103, in pydantic_encoder
    raise TypeError(f"Object of type '{obj.__class__.__name__}' is not JSON serializable")
TypeError: Object of type 'Url' is not JSON serializable

Expected behavior
Url is pydantic type and should be serialized to str. The issue caused by calling deprecated pydantic_encoder

Additional context
Not sure if there are other cases of new pydantic not supported, but probably uplink should require pydantic<2

@djbios djbios linked a pull request Jul 19, 2023 that will close this issue
@leiserfg
Copy link
Contributor

leiserfg commented Sep 8, 2023

I have intentions of adding support for Pydantic 2, but @prkumar does not seem to be available sadly.

@djbios djbios linked a pull request Jan 31, 2024 that will close this issue
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 a pull request may close this issue.

2 participants