How do I set validate_by_alias only at model_validate() time?

2 weeks ago 12
ARTICLE AD BOX

I don't want to hard code validate_by_alias=True|False via ConfigDict. I also don't want to do something wonky like subclassing and setting different ConfigDict settings. I just want to be able to instantiate with or without aliases.

Sometimes I want to instantiate with aliases and sometimes I don't.

Is there a way of doing something like this?

MyModel.model_validate(obj, validate_by_alias=True|False)

How can I toggle this at validation time?

Read Entire Article