cognitedata / transformations-cli

Apache License 2.0
2 stars 1 forks source link

Error during exit_with_cognite_api_error #56

Open sdorheim opened 2 years ago

sdorheim commented 2 years ago

When trying to deploy a transformation to bluefield I get an API error, but the CLI crashes before it can output the actual error message. Below you can see the trace of the error.

Deploying transformations...
Traceback (most recent call last):
  File "~/transformations-cli/cognite/transformations_cli/commands/deploy/transformations_api.py", line 229, in upsert_transformations
    client.transformations.create(c)
  File "/lib/python3.10/site-packages/cognite/client/_api/transformations/__init__.py", line 60, in create
    return self._create_multiple(transformation)
  File "/lib/python3.10/site-packages/cognite/client/_api_client.py", line 567, in _create_multiple
    summary.raise_compound_exception_if_failed_tasks(
  File "/lib/python3.10/site-packages/cognite/client/utils/_concurrency.py", line 53, in raise_compound_exception_if_failed_tasks
    collect_exc_info_and_raise(
  File "/lib/python3.10/site-packages/cognite/client/utils/_concurrency.py", line 85, in collect_exc_info_and_raise
    raise CogniteAPIError(
cognite.client.exceptions.CogniteAPIError: <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "~/transformations-cli/cognite/transformations_cli/__main__.py", line 5, in main
    transformations_cli()
  File "/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/lib/python3.10/site-packages/click/decorators.py", line 38, in new_func
    return f(get_current_context().obj, *args, **kwargs)
  File "~/transformations-cli/cognite/transformations_cli/commands/deploy/deploy.py", line 107, in deploy
    _, updated_transformations, created_transformations = upsert_transformations(
  File "~/transformations-cli/cognite/transformations_cli/commands/deploy/transformations_api.py", line 232, in upsert_transformations
    exit_with_cognite_api_error(e)
  File "~/transformations-cli/cognite/transformations_cli/commands/utils.py", line 48, in exit_with_cognite_api_error
    sys.exit(f"Cognite API error has occurred: {e}")
  File "/lib/python3.10/site-packages/cognite/client/exceptions.py", line 101, in __str__
    msg += self._get_multi_exception_summary()
  File "/lib/python3.10/site-packages/cognite/client/exceptions.py", line 33, in _get_multi_exception_summary
    [self._unwrap_fn(f) for f in self.failed],
  File "/lib/python3.10/site-packages/cognite/client/exceptions.py", line 33, in <listcomp>
    [self._unwrap_fn(f) for f in self.failed],
  File "/lib/python3.10/site-packages/cognite/client/_api_client.py", line 561, in str_format_element
    dumped = el.dump()
  File "/lib/python3.10/site-packages/cognite/client/data_classes/transformations/__init__.py", line 159, in dump
    ret[source_key] = self.source_oidc_credentials.dump(camel_case=camel_case)
AttributeError: 'dict' object has no attribute 'dump'

Debugging the issue a bit further I could find out the the error that causes the failure is of type: " <class 'cognite.client.exceptions.CogniteAPIError'> " with message: "Can not write transformation with dataSetId: null."

sdorheim commented 2 years ago

The manifest that triggered the issue. Adding a correct dataSetExternalId where the deploy-principal had access solved the API-error.

externalId: "cdf:assets:upsert:tr-001:assets"
name: "cdf:assets:upsert:tr-001:assets"
destination: 
  type: "asset_hierarchy"
shared: True
action: "upsert"
query: 
  file: "assets.sql"
ignoreNullFields: False
notifications:
  - aaa.bbb@ccc.com
authentication:
  clientId: ${RUN_AS_CLIENT_ID}
  clientSecret: ${RUN_AS_CLIENT_SECRET}
  tokenUrl: ${TRANSFORMATIONS_TOKEN_URL}
  scopes: 
    - ${TRANSFORMATIONS_SCOPES}
  cdfProjectName: ${TRANSFORMATIONS_PROJECT}
vvemel commented 2 years ago

Created a bug from this issue report https://cognitedata.atlassian.net/browse/CDF-15431 FYI @SunilVenekarKrishnamoorthy

vvemel commented 2 years ago

Hi @sdorheim, sorry for the delay. We fixed the issue, can you validate if it works for you? (I understand if you don't remember the issue, it's been a while :D) If it is fixed on your end, I'll close this issue.