Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set parameter 'name' as required (as required in UI) for DataModelApply in cognite-sdk #1620

Closed
eighty20results opened this issue Feb 13, 2024 · 3 comments
Labels

Comments

@eighty20results
Copy link

  1. 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)

  1. 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.

@haakonvt
Copy link
Contributor

Ping @doctrino

@doctrino
Copy link
Contributor

doctrino commented Mar 6, 2024

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:

  1. Set ‘name’ as required for DataModelApply.
  2. 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.

@doctrino
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants