skip to Main Content

Centos – pydantic model incorrectly applies validation

I have a model defined like this; class SomeModel(BaseModel): name: str class SomeOtherModel(BaseModel): name: int class MyModel(BaseModel): items: List[Union[SomeModel, SomeOtherModel]] @validator("items", always=True) def validate(cls, value): by_type = list(filter(lambda v: isinstance(v, SomeModel), value)) if len(by_type) < 1: raise ValueError("we need at…

VIEW QUESTION
Back To Top
Search