Why does pydantic not validate an argument that is the list of Foo objects but throws ValidationError when the argument is a list of primitive types?
Can I enforce the validation of complex types?
Validation doesn't work:
from typing import List
from pydantic import BaseModel
class Foo(BaseModel):
kind: str = "foo"
class Bar(BaseModel):
kind: str = "bar"
class Spam(BaseModel):
foos: List[Foo]
spam = Spam(foos=[Bar()])
print(spam.dict())
>>> {'foos': [{'kind': 'bar'}]}
Validation works:
class Spam(BaseModel):
foos: List[int]
spam = Spam(foos=[Bar()])
print(spam.dict())
pydantic.error_wrappers.ValidationError: 1 validation error for Spam
foos -> 0
value is not a valid integer (type=type_error.integer)