-
Notifications
You must be signed in to change notification settings - Fork 280
Ensure ValidationInfo.field_name
is correct on validator reuse
#1692
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
Conversation
…e called with correct ValidationInfo.field_name
@davidhewitt Please review! cc @Viicos Edit: Never mind, failing tests, looking |
CodSpeed Performance ReportMerging #1692 will not alter performanceComparing Summary
|
I ended up changing some tests in 0fd7ef1 and df34451. Both are similar to the issue described in pydantic/pydantic#11737 (comment): we now get I think the changes in the second commit make sense as the validator acts on the field value, but not necessarily in first commit where the validator acts on the entire model. I'm not sure the State based approach gives us the ability to drop the @Viicos What do you thnk? |
We're hitting some leak/GC issues! https://github.com/pydantic/pydantic-core/actions/runs/14476861875/job/40604489000?pr=1692 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looking good!
These might be reproducable on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with just the question of maybe we start cleaning up the existing state to keep things efficient.
The 3.13t tests will not block merge, so depending on whether we leave the above for a follow-up this is good to go 👍
You mean having the state rebound only if we are certain a validator (with info) is going to be used? |
Nope I just meant the deprecation which you agreed with. 👍 |
…plain,wrap}_validator_function
@@ -1954,7 +1954,7 @@ class NoInfoValidatorFunctionSchema(TypedDict): | |||
class WithInfoValidatorFunctionSchema(TypedDict, total=False): | |||
type: Required[Literal['with-info']] | |||
function: Required[WithInfoValidatorFunction] | |||
field_name: str | |||
field_name: str # deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this TypedDict
is only used for type hinting -- let me know if this is sufficient or if we should force a deprecation warning here as well somehow.
# insert_assert(reprs) | ||
assert reprs == [ | ||
'ValidationInfo(config=None, context=None, data=None, field_name=None)', | ||
"ValidationInfo(config=None, context=None, data=None, field_name='x')", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test explicitly tested the now-deprecated behavior of setting a field_name
on the validator function schema. If we assume no one was directly constructing these instead of us, removing this should be fine.
I could also leave the test and wrap the call in pytest.warns
, to verify the old behavior keeps working (which it does) -- let me know what you prefer.
@Viicos Pydantic is still passing What's the best way to update pydantic for the new pydantic-core, before this is even merged? |
ValidationInfo.field_name
is correct on validator reuse
I think this is fine, it is actually not a change in behavior as it is already behaving as such (as per my comment). Would be great if this wasn't this way but anyway I don't think many users are relying on this
We usually skip it as it will work again once the pydantic-core version is bumped on pydantic. |
@Viicos OK, I'll get a PR up to stop passing the |
Companion PR in Pydantic: pydantic/pydantic#11761 cc @Viicos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good, thanks 👍
@Viicos Let me know when you've bumped the version here and I'll update the Pydantic PR to point at the new version! |
Change Summary
See pydantic/pydantic#11737 (comment)
Companion PR in pydantic: pydantic/pydantic#11761
Related issue number
Part of pydantic/pydantic#11737
Checklist
pydantic-core
(except for expected changes)Selected Reviewer: @sydney-runkle