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
First of all, thanks for the great work! And sorry if this request is not qualified as a "bug"
Context:
I am currently migrating from the v1 API to v2 and encountered a small hurdle related to the usage of always in the validator section.
While going through the pages, I found it slightly convoluted to find the doc with this particular migration or at least identify the closest alternative in the v2 API. After some exploration, I stumbled upon the validate_default argument in the Field API, which seems to offer the closest behavior to what I need.
However, it took some effort to discover this option. I believe it would greatly benefit the community if we could clarify this usage in the migration guide and the field validator documentation. To contribute, I will be happy to create a quick PR to update the doc.
If you use the always=True keyword argument to a validator function, note that standard validators for the annotated type will also be applied even to defaults, not just the custom validators. For example, despite the fact that the validator below will never error, the following code raises a ValidationError:
Initial Checks
Description
Hello team,
First of all, thanks for the great work! And sorry if this request is not qualified as a "bug"
Context:
I am currently migrating from the v1 API to v2 and encountered a small hurdle related to the usage of
always
in the validator section.While going through the pages, I found it slightly convoluted to find the doc with this particular migration or at least identify the closest alternative in the v2 API. After some exploration, I stumbled upon the
validate_default
argument in the Field API, which seems to offer the closest behavior to what I need.However, it took some effort to discover this option. I believe it would greatly benefit the community if we could clarify this usage in the migration guide and the field validator documentation. To contribute, I will be happy to create a quick PR to update the doc.
Thanks again.
Example Code
The following are the confusing parts:
but it never mentioned
how to
migrate to v2The default value doesn't seem to be
True
since the behaviors of puttingTrue
or leaving it as "default" differ.Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: