Skip to content

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

Merged
samuelcolvin merged 9 commits into
mainfrom
ValdationInfo
Sep 22, 2023
Merged

samuelcolvin merged 9 commits into
mainfrom
ValdationInfo

Conversation

@samuelcolvin

@samuelcolvin samuelcolvin commented Sep 21, 2023

Copy link
Copy Markdown
Member

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

cloudflare-workers-and-pages Bot commented Sep 21, 2023

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
xsedla1o added a commit to CESNET/dp3 that referenced this pull request Jun 4, 2026
Has been deprecated [for a while now](pydantic/pydantic#7542),
was somehow overlooked in previous iterations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants