8000 Allow access to `field_name` and `data` in all validators if there is data and a field name by samuelcolvin · Pull Request #7542 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

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-workers-and-pages
Copy link
cloudflare-workers-and-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
@samuelcolvin samuelcolvin deleted the ValdationInfo branch September 22, 2023 10:26
@Viicos Viicos mentioned this pull request Jan 8, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants

0