-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
model_validate returns None #7055
Comments
Could you please provide more info/a MRE? I can't reproduce: from pydantic import BaseModel
class ParametersModel(BaseModel):
TemplatesBucket: str
class Model(BaseModel):
StackName: str
TemplateURL: str
Parameters: ParametersModel
@classmethod
def create_example(cls) -> str:
example_data = {
"StackName": "my-stack",
"TemplateURL": "https://my-bucket.s3.amazonaws.com/my-template.yaml",
"Parameters": {"TemplatesBucket": "FAKE"},
}
example_config = cls.model_validate(example_data)
print(example_config)
Model.create_example()
#> StackName='my-stack' TemplateURL='https://my-bucket.s3.amazonaws.com/my-template.yaml' Parameters=ParametersModel(TemplatesBucket='FAKE') |
Since we can't reproduce, I'll be closing the issue. @shadycuz Please create a new issue with a reproducible example. 🙏 |
I have also come across this behaviour. Unfortunately, the place I am seeing it is pretty complicated (lots of subclassing and mixins) so I can't easily give a MWE. Anyway, just commenting to show that this is not a totally isolated case, but I'm also pretty confident that I've done something stupid somewhere so I don't think it's worth re-opening... Edit: |
Initial Checks
Description
When using
MyModel.model_validate
, it returnsNone
.This works:
This doesn't:
output:
Example Code
No response
Python, Pydantic & OS Version
Selected Assignee: @adriangb
Edit: My use case for
model_validate()
is I need to providecontext
for some of my field validators.The text was updated successfully, but these errors were encountered: