-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 dataclasses cannot be used as Annotated Validators #9443
Comments
Hi @salemileandro, Thanks for the question! Indeed, looks like a conflict on the I'll take a closer look at this for 2.8 and see if we can come up with a workaround for you! |
Hi @salemileandro, After chatting about this a bit more with the team, we've decided that we'd recommend just using plain dataclasses as annotated metadata for now. We can revisit this for V3, but I'm going to remove this from the v2.8.0 milestone 👍 |
Hi! |
Initial Checks
Description
Pydantic dataclasses cannot be used as Annotated Validators. The TypeError happens at class the definition.
I wanted to replicate the example of the section As a method on a custom type of the "Types" part of the Concepts but instead of using Python dataclasses, I wanted to use Pydantic dataclasses (to add validation).
I am not sure about all the internals but it looks like some conflicts about the
__get_pydantic_core_schema__
that needs to be implemented for the class to be an Annotated Validator and the__get_pydantic_core_schema__
that is used for the definition.I've read in the Pydantic website that
[...] you should try to stick to the built-in constructs like those provided by annotated-types, pydantic.Field, or BeforeValidator and so on.
, so sorry if this is somehow already known and I should just avoid using Pydantic dataclasses in this specific context.Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: