Hello! Does any common way to throw an error for an empty input value?
Example:
class Foo(pydantic.BaseModel):
bar: str
# Wanna throw an error in this case
Foo(bar="")
Thank you for your work.
You can use constr as a type.
from pydantic import constr, BaseModel
class Model(BaseModel):
bar: constr(min_length=1)
Model(bar="")
https://pydantic-docs.helpmanual.io/usage/types/#constrained-types
or you can use validators
Most helpful comment
You can use
constras a type.https://pydantic-docs.helpmanual.io/usage/types/#constrained-types