From 79a655f6af0279f23f4cf6447f978d029c4febde Mon Sep 17 00:00:00 2001 From: Anders Albert <60234212+doctrino@users.noreply.github.com> Date: Thu, 14 Sep 2023 21:10:08 +0200 Subject: [PATCH] feat: ignore unknown ids in functions (#1372) --- CHANGELOG.md | 4 ++++ cognite/client/_api/functions.py | 7 ++++++- cognite/client/_version.py | 2 +- pyproject.toml | 2 +- .../test_api/test_functions.py | 18 ++++++++++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 tests/tests_integration/test_api/test_functions.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 822a0ce541..8e5e384560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [6.25.0] - 2023-09-14 +### Added +- Support for `ignore_unknown_ids` in `client.functions.retrieve_multiple` method. +- ## [6.24.1] - 2023-09-13 ### Fixed - Bugfix for `AssetsAPI.create_hierarchy` when running in upsert mode: It could skip certain updates above diff --git a/cognite/client/_api/functions.py b/cognite/client/_api/functions.py index eb0f01f906..3bbdfe3d62 100644 --- a/cognite/client/_api/functions.py +++ b/cognite/client/_api/functions.py @@ -318,13 +318,17 @@ def retrieve(self, id: int | None = None, external_id: str | None = None) -> Fun return self._retrieve_multiple(identifiers=identifier, resource_cls=Function, list_cls=FunctionList) def retrieve_multiple( - self, ids: Sequence[int] | None = None, external_ids: Sequence[str] | None = None + self, + ids: Sequence[int] | None = None, + external_ids: Sequence[str] | None = None, + ignore_unknown_ids: bool = False, ) -> FunctionList | Function | None: """`Retrieve multiple functions by id. `_ Args: ids (Sequence[int] | None): IDs external_ids (Sequence[str] | None): External IDs + ignore_unknown_ids (bool): Ignore IDs and external IDs that are not found rather than throw an exception. Returns: FunctionList | Function | None: The requested functions. @@ -349,6 +353,7 @@ def retrieve_multiple( identifiers=IdentifierSequence.load(ids=ids, external_ids=external_ids), resource_cls=Function, list_cls=FunctionList, + ignore_unknown_ids=ignore_unknown_ids, ) def call( diff --git a/cognite/client/_version.py b/cognite/client/_version.py index dde3c4639b..9bf90a7f0c 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "6.24.1" +__version__ = "6.25.0" __api_subversion__ = "V20220125" diff --git a/pyproject.toml b/pyproject.toml index aa82a96b0e..b62c988591 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "6.24.1" +version = "6.25.0" description = "Cognite Python SDK" readme = "README.md" diff --git a/tests/tests_integration/test_api/test_functions.py b/tests/tests_integration/test_api/test_functions.py new file mode 100644 index 0000000000..58a9b3aa15 --- /dev/null +++ b/tests/tests_integration/test_api/test_functions.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +import pytest + +from cognite.client import CogniteClient +from cognite.client.exceptions import CogniteNotFoundError + + +class TestFunctionsAPI: + def test_retrieve_unknown_raises_error(self, cognite_client: CogniteClient): + with pytest.raises(CogniteNotFoundError) as e: + cognite_client.functions.retrieve_multiple(external_ids=["this does not exist"]) + + assert e.value.not_found[0]["external_id"] == "this does not exist" + + def test_retrieve_unknown_ignore_unknowns(self, cognite_client: CogniteClient): + res = cognite_client.functions.retrieve_multiple(external_ids=["this does not exist"], ignore_unknown_ids=True) + assert len(res) == 0