Skip to content

Instantly share code, notes, and snippets.

@Viicos
Created May 7, 2024 12:07
Show Gist options
  • Save Viicos/d7b25251453a050c198c76dede34cf1b to your computer and use it in GitHub Desktop.
Save Viicos/d7b25251453a050c198c76dede34cf1b to your computer and use it in GitHub Desktop.
from pydantic import BaseModel
class Model(BaseModel):
model_config = {
"validate_default": True,
}
class MyModel(Model):
model_config = {
"str_max_length": 2,
}
a: int = "not_an_int"
b: str
MyModel(b="more_than_two_chars")
#> Will raise two validation errors, one for the default value of `a`, the other for `b` being longer than two chars.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment