-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
context not passed to field validators #407
Comments
Thanks @aidanmontare-fed for reporting this bug. I will prepare a fix. |
@aidanmontare-fed I created #417 to fix the problem. Could you please confirm? |
@hramezani just checked it out and it works great! Thanks so much! |
Thanks @aidanmontare-fed for reporting the bug and confirming the fix. The fix will be available in the next release! |
@aidanmontare-fed I have to revert the fix. The fix that I did caused a lot of issues for current users and had to be reverted. Here are some of the issues:
You can solve your problem by adding class Settings(BaseSettings):
text: str
def __init__(self, **data):
super().__init__(**data)
__init__.__pydantic_base_init__ = True
@field_validator('text')
@classmethod
def test_validator(cls, v: str, info: ValidationInfo):
context = info.context
print(f'{context=}')
if context:
print('have context')
return v
Settings.model_validate({'text': 'foo bar'}, context={'biz': 'baz'}) |
moving here from #pydantic/pydantic#10418
Initial Checks
Description
Hi there! It appears that the
context
arg that can be passed tomodel_validate
does not work when using Pydantic Settings, when it does work using a regular Pydantic model.Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: