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.
Uh oh!
There was an error while loading. Please reload this page.
-
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
DandiBaseModelmodel 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_factoryordefault.If my guess is correct, then there is a problem with this method.
BaseModel.constructin the Pydantic V1 (as of the latest version but not sure about earlier version) fulfills the purpose above.BaseModel.model_constructin Pydantic V2 fulfills the purpose above as documented in https://docs.pydantic.dev/latest/api/base_model/#pydantic.main.BaseModel.model_construct.xin the follow model is required and doesn't have a default. However, the logic of theunvalidatedmethod would set thexattribute of the produced model instance toNonein Pydantic V1 andPydanticUndefinedin Pydantic V2.Beta Was this translation helpful? Give feedback.
All reactions