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
importpydanticfromtypingimportType, Sequence, UnionclassT:
passclassModel(pydantic.BaseModel):
t: Union[Type[T], Sequence[Type[T]]] =T@pydantic.validator("t", always=True)defmake_tuple(cls, v):
ifisinstance(v, Sequence):
returntuple(v)
returnv,
# ConfigError: Validators defined with incorrect fields: make_tuple (use check_fields=False if you're inheriting from the model and intended this)
Note: If the field is marked optional and the default value is set to None, the code works without issue.
Hello @ntenenz and thanks for reporting!
It looks like a bug. It seems like the default value with this type is not taken into account in the metaclass causing Model.__fields__ to not have the t key, which causes this error.
In the meantime you can use Field to force it: t: Union[Type[T], Sequence[Type[T]]] = Field(T)
EDIT: opened a PR with the fix :)
Happy holiday season 🎅
PrettyWood
added a commit
to PrettyWood/pydantic
that referenced
this issue
Dec 22, 2020
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:Note: If the field is marked optional and the default value is set to
None
, the code works without issue.Perhaps I am missing something obvious in my sleep-deprived stupor?
The text was updated successfully, but these errors were encountered: