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

Sample request: Pydantic v2 converter #97

Open
cretz opened this issue Nov 30, 2023 · 3 comments
Open

Sample request: Pydantic v2 converter #97

cretz opened this issue Nov 30, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@cretz
Copy link
Member

cretz commented Nov 30, 2023

Describe the solution you'd like

Rename sample pydantic_converter to pydanticv1_converter (and tests/packages/dep-group/etc) and make a new pydantic_converter sample that works with v2

@cretz cretz added the enhancement New feature or request label Nov 30, 2023
@cretz cretz changed the title Sample request: Pydantic v2 Sample request: Pydantic v2 converter Nov 30, 2023
@JaneJeon
Copy link

I am setting up a new project and I would really appreciate this for the "type safety without having to redefine attributes twice" benefits!

In particular, the pydantic_encoder does not work anymore in v2: pydantic/pydantic#6652

@cretz
Copy link
Member Author

cretz commented Jan 24, 2024

Until the sample is present, you can apply the concepts/approaches of the custom conversion to whatever is needed for v2 without applying the specific code

@slingshotvfx
Copy link

@JaneJeon I am using pydantic 2 with temporal just by changing pydantic_encoder to to_jsonable_python:

from pydantic_core import to_jsonable_python

...
        # We let JSON conversion errors be thrown to caller
        return Payload(
            metadata={"encoding": self.encoding.encode()},
            data=json.dumps(value, separators=(",", ":"), sort_keys=True, default=to_jsonable_python).encode(),
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants