Set parameter 'name' as required (as required in UI) for DataModelApply in cognite-sdk
Closed this issue · 3 comments
- Field ‘name’ is required during creating data model in CDF. But it is not required if create through SDK:
data_models = [DataModelApply(space="mySpace",external_id="myDataModel",version="v1")] c.data_modeling.data_models.apply(data_models)
- For data models have values in ‘name’ and ‘description’ fields these fields would be cleared up if these parameters are not specified in DataModelApply.
These code will clear name and description values (if ‘myDataModel’ had them):
data_models = [DataModelApply(space="mySpace",external_id="myDataModel",version="v1")] c.data_modeling.data_models.apply(data_models)
These code won’t clear name and description values (if ‘myDataModel’ had them):data_models = [DataModelApply(space="mySpace",external_id="myDataModel",version="v1", name=”myDataModel”, description=”My Description”)]
c.data_modeling.data_models.apply(data_models)
To fix make changes in cognite-sdk:Set ‘name’ as required for DataModelApply.
Fix clearing values from name and description in DataModelApply when these parameters are not specified.
Two things here on the question
First, the two code snippets are identical, so I do not understand why the first clears name and description and the second don't.
The solution seems like a contradiction:
- Set ‘name’ as required for DataModelApply.
- Fix clearing values from name and description in DataModelApply when these parameters are not specified.
You cannot require name (1.) and not 'clear' values when name is not specified (2.)
Answer.
First, this seems to be an issue of the API and not the SDK. When you set name and description to None, the SDK does not send them when you call the apply methdod
DataModelApply(
space="sp_sandbox_doctrino",
external_id="my_data_model",
version="1"
).dump()
>>> {'space': 'sp_sandbox_doctrino', 'externalId': 'my_data_model', 'version': '1'}
Second, the SDK is not an application like the UI is. It is a tool for developers and I do not think the SDK should put an extra restriction on the name parameter and make it required when the API has it as optional.
I have looked into this issue some more.
First name
is not required and thus should be optional.
Second, the updating of description and name works as expected. If you set the them to any value including None in an existing model, they will be updated.