You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scenario:
Adding @model_validator methods to a Pydantic model.
Example:
fromtypingimportAny, Selffrompydanticimportmodel_validator, ConfigDict, BaseModel, FieldclassExampleModel(BaseModel):
"""An example model."""field_without_default: str"""Shows the *[Required]* marker in the signature."""field_plain_with_validator: int=100"""Show standard field with type annotation."""@model_validator(mode="before")@classmethoddeflowercase_only(cls, data: dict[str, Any]) ->dict[str, Any]:
ifisinstance(data.get("field_without_default"), str):
data["field_without_default"] =data["field_without_default"].lower()
returndata@model_validator(mode="after")defat_least_one_truthy_field(self) ->Self:
"""At least one field should be truthy. """assert (self.field_without_defaultorself.field_plain_with_validator)
returnself
Expected behaviour:
@model_validator methods listed under heading "Validators" (similar to how @field_validtor methods are rendered)
@model_validator methods labeled as pydantic-validator or similar (similar to how @field_validator methods are labelled)
Actual behaviour:
Methods appear in MkDocs as a regular class method or instance method. Not listed under "Validators"
The text was updated successfully, but these errors were encountered:
Scenario:
Adding
@model_validator
methods to a Pydantic model.Example:
Expected behaviour:
@model_validator
methods listed under heading "Validators" (similar to how@field_validtor
methods are rendered)@model_validator
methods labeled aspydantic-validator
or similar (similar to how@field_validator
methods are labelled)Actual behaviour:
Methods appear in MkDocs as a regular class method or instance method. Not listed under "Validators"
The text was updated successfully, but these errors were encountered: