Skip to content

Commit

Permalink
feat: ignore unknown ids in functions (#1372)
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino authored Sep 14, 2023
1 parent 9d88fd9 commit 79a655f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion cognite/client/_api/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. <https://developer.cognite.com/api#tag/Functions/operation/byIdsFunctions>`_
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.
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations

__version__ = "6.24.1"
__version__ = "6.25.0"
__api_subversion__ = "V20220125"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "cognite-sdk"

version = "6.24.1"
version = "6.25.0"

description = "Cognite Python SDK"
readme = "README.md"
Expand Down
18 changes: 18 additions & 0 deletions tests/tests_integration/test_api/test_functions.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 79a655f

Please sign in to comment.