Skip to content

Tag: pydantic

override field alias from subclass in Pydantic

I have 2 models, 1 subclassing the other: How can I accomplish this ? Answer You don’t need to subclass to accomplish what you want (unless your need is more complex than your example). For import: Add the Config option to allow_population_by_field_name so you can add the data with names or firstnames F…

How to reuse a root_validator in Pydantic?

The Pydantic docs have an example of reusing a validator: https://pydantic-docs.helpmanual.io/usage/validators/#reuse-validators Is it possible to reuse a root validator? Answer Yes, it is possible and the API is very similiar Example: It is also possible to parameterize the validator like in this example htt…