Update relationships
- async AsyncCogniteClient.relationships.update(
- item: Relationship | RelationshipWrite | RelationshipUpdate | Sequence[Relationship | RelationshipWrite | RelationshipUpdate],
- mode: Literal['replace_ignore_null', 'patch', 'replace'] = 'replace_ignore_null',
Update one or more relationships.
Currently, a full replacement of labels on a relationship is not supported (only partial add/remove updates). See the example below on how to perform partial labels update.
- Parameters:
item (Relationship | RelationshipWrite | RelationshipUpdate | Sequence[Relationship | RelationshipWrite | RelationshipUpdate]) – Relationship(s) to update
mode (Literal['replace_ignore_null', 'patch', 'replace']) – How to update data when a non-update object is given (Relationship or -Write). If you use ‘replace_ignore_null’, only the fields you have set will be used to replace existing (default). Using ‘replace’ will additionally clear all the fields that are not specified by you. Last option, ‘patch’, will update only the fields you have set and for container-like fields such as metadata or labels, add the values to the existing. For more details, see Update and Upsert Mode Parameter.
- Returns:
Updated relationship(s)
- Return type:
Examples
Update a data set that you have fetched. This will perform a full update of the data set:
>>> from cognite.client import CogniteClient, AsyncCogniteClient >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> rel = client.relationships.retrieve(external_id="flow1") >>> rel.confidence = 0.75 >>> res = client.relationships.update(rel)
Perform a partial update on a relationship, setting a source_external_id and a confidence:
>>> from cognite.client.data_classes import RelationshipUpdate >>> my_update = ( ... RelationshipUpdate(external_id="flow_1") ... .source_external_id.set("alternate_source") ... .confidence.set(0.97) ... ) >>> res1 = client.relationships.update(my_update) >>> # Remove an already set optional field like so >>> another_update = RelationshipUpdate(external_id="flow_1").confidence.set(None) >>> res2 = client.relationships.update(another_update)
Attach labels to a relationship:
>>> from cognite.client.data_classes import RelationshipUpdate >>> my_update = RelationshipUpdate(external_id="flow_1").labels.add(["PUMP", "VERIFIED"]) >>> res = client.relationships.update(my_update)
Detach a single label from a relationship:
>>> from cognite.client.data_classes import RelationshipUpdate >>> my_update = RelationshipUpdate(external_id="flow_1").labels.remove("PUMP") >>> res = client.relationships.update(my_update)