cognitedata/cognite-sdk-js

Automatic chunking on assets.delete fails

Closed this issue · 2 comments

Assume you have a list (assetIds) of asset ids you want to delete. The list of asset ids represents an asset hierarchy with 1 root and 1000 direct children. The list looks like this: [root, child1, child2, ..., child999, child1000].

If you call client.assets.delete(assetIds.map(assetId => ({ id: assetId }))) #176 will automatically chunk your delete-request into two API-calls:

  1. Delete [root, child1, child2, ..., child999]
  2. Delete [child1000]

If the API-calls is executed in that order then the 2nd request will fail with 400 (didn't find the asset). The reason for this is that the root-asset was deleted in the 1st API-call and therefore deleted the entire subtree.

Since the execution order matters (API-call 2 and then API-call 1 will not fail) and since the SDK cannot control it if we want to parallelise then it doesn't make sense to return info about failed requests to the end-user.

We can solve this by parsing the 400-response and look for objects in the missing array (array of asset ids that don't exist) and remove them from our requests before we retry the request.

Cognite is currently discussing internally if we want to introduce a new parameter to the delete-asset endpoint for silently ignoring unknown IDs. Putting SDK fix on hold

Moved to JIRA