What is the purpose of DandiBaseModel.unvalidated
?
#202
Replies: 3 comments 5 replies
-
attn @satra and @jwodder who would know better. FWIW |
Beta Was this translation helpful? Give feedback.
-
As far as I understood it, I fully support eliminating this method and making it impossible to construct invalid metadata objects. If we want to be able to accept user input that lacks fields, then we should have a model that actually declares those fields optional. |
Beta Was this translation helpful? Give feedback.
-
FTR: |
Beta Was this translation helpful? Give feedback.
-
What is the purpose of
DandiBaseModel.unvalidated
?dandi-schema/dandischema/models.py
Lines 398 to 414 in 68f4d1e
It seems to me that it is for creating a
DandiBaseModel
model object (or an object of a subclass ofDandiBaseModel
) without going through the validation process provided by Pydantic but keeping the default value either provided by thedefault_factory
ordefault
.If my guess is correct, then there is a problem with this method.
BaseModel.construct
in the Pydantic V1 (as of the latest version but not sure about earlier version) fulfills the purpose above.BaseModel.model_construct
in Pydantic V2 fulfills the purpose above as documented in https://docs.pydantic.dev/latest/api/base_model/#pydantic.main.BaseModel.model_construct.x
in the follow model is required and doesn't have a default. However, the logic of theunvalidated
method would set thex
attribute of the produced model instance toNone
in Pydantic V1 andPydanticUndefined
in Pydantic V2.Beta Was this translation helpful? Give feedback.
All reactions