From 454365839e0eac3d63aaac9899df2779d9f02d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Murad=20S=C3=A6ter?= <51971968+muradsater@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:06:06 +0100 Subject: [PATCH] Add example on how to update the nonce for transformations (#1517) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: HÃ¥kon V. Treider --- .../client/_api/transformations/__init__.py | 23 +++++++++++++++---- .../data_classes/transformations/__init__.py | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cognite/client/_api/transformations/__init__.py b/cognite/client/_api/transformations/__init__.py index 2d40d74158..e42505ddab 100644 --- a/cognite/client/_api/transformations/__init__.py +++ b/cognite/client/_api/transformations/__init__.py @@ -299,15 +299,28 @@ def update( Perform a partial update on a transformation, updating the query and making it private:: - >>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import TransformationUpdate - >>> c = CogniteClient() >>> my_update = TransformationUpdate(id=1).query.set("SELECT * FROM _cdf.assets").is_public.set(False) >>> res = c.transformations.update(my_update) - """ + Update the session used for reading (source) and writing (destination) when authenticating for all + transformations in a given data set: + + >>> from cognite.client.data_classes import NonceCredentials + >>> to_update = c.transformations.list(data_set_external_ids=["foo"]) + >>> new_session = c.iam.sessions.create() + >>> new_nonce = NonceCredentials( + ... session_id=new_session.id, + ... nonce=new_session.nonce, + ... cdf_project_name=c.config.project + ... ) + >>> for tr in to_update: + ... tr.source_nonce = new_nonce + ... tr.destination_nonce = new_nonce + >>> res = c.transformations.update(to_update) + """ if isinstance(item, Sequence): - item = list(item).copy() + item = list(item) sessions: dict[str, NonceCredentials] = {} for i, t in enumerate(item): if isinstance(t, Transformation): @@ -321,7 +334,7 @@ def update( item._process_credentials(keep_none=True) elif not isinstance(item, TransformationUpdate): raise TypeError( - "item must be Sequence[Transformation], Transformation, Sequence[TransformationUpdate] or TransformationUpdate" + "item must be one of: TransformationUpdate, Transformation, Sequence[TransformationUpdate | Transformation]." ) return self._update_multiple( diff --git a/cognite/client/data_classes/transformations/__init__.py b/cognite/client/data_classes/transformations/__init__.py index 0eba005c6c..b994334a95 100644 --- a/cognite/client/data_classes/transformations/__init__.py +++ b/cognite/client/data_classes/transformations/__init__.py @@ -519,7 +519,7 @@ class TransformationFilter(CogniteFilter): has_blocked_error (bool | None): Whether only the blocked transformations should be included in the results. created_time (dict[str, Any] | TimestampRange | None): Range between two timestamps last_updated_time (dict[str, Any] | TimestampRange | None): Range between two timestamps - data_set_ids (list[dict[str, Any]] | None): Return only transformations in the specified data sets with these ids. + data_set_ids (list[dict[str, Any]] | None): Return only transformations in the specified data sets with these ids, e.g. [{"id": 1}, {"externalId": "foo"}]. tags (TagsFilter | None): Return only the resource matching the specified tags constraints. It only supports ContainsAny as of now. """