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

Allow access to field_name and data in all validators if there is data and a field name #7542

Merged
merged 9 commits into from Sep 22, 2023

Conversation

samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Sep 21, 2023

Companion to pydantic/pydantic-core#980.

Also results in significant simplification of the types in pydantic-core.

Note: because of this, some type annotations and function from pydantic_core.core_schema have been changed.

Fix #7448
fix #6794
Fix #6345

TODO:

  • release pydantic-core with the PR merged
  • update the docs
  • check the above issues really are solved by this

Selected Reviewer: @adriangb

@cloudflare-pages
Copy link

cloudflare-pages bot commented Sep 21, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ade9bc0
Status: ✅  Deploy successful!
Preview URL: https://1d8a4f52.pydantic-docs2.pages.dev
Branch Preview URL: https://valdationinfo.pydantic-docs2.pages.dev

View logs

@samuelcolvin samuelcolvin marked this pull request as ready for review September 21, 2023 20:25
@samuelcolvin
Copy link
Member Author

please review.

!!!note
This was not possible with Pydantic V2 to V2.3, it was [re-added](https://github.com/pydantic/pydantic/pull/7542) in Pydantic V2.4.

As of Pydantic V2.4, you can access the field name via the `handler.field_name` within `__get_pydantic_core_schema__`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize we were doing this. This ties us even more into the type != schema paradigm. Was this possible in v1? If we made the field name a runtime thing in core would this still be necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, but it's the only way to make what we're doing possible.

@samuelcolvin samuelcolvin enabled auto-merge (squash) September 22, 2023 10:21
@samuelcolvin samuelcolvin merged commit dd2826e into main Sep 22, 2023
57 checks passed
@samuelcolvin samuelcolvin deleted the ValdationInfo branch September 22, 2023 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment