From 929adcb6f6ec9a01605cfa1db2590ff84f4f04d8 Mon Sep 17 00:00:00 2001 From: Anders Albert <60234212+doctrino@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:21:21 +0200 Subject: [PATCH] Query optional in instance.search (#1905) --- CHANGELOG.md | 4 ++++ .../client/_api/data_modeling/instances.py | 20 ++++++++++++------- cognite/client/_version.py | 2 +- pyproject.toml | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c99ca06ef..5b72c42eec 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. +## [7.58.3] - 2024-09-03 +### Fixed +- The parameter `query` is now optional in `client.data_modeling.instances.search(...)`. + ## [7.58.2] - 2024-09-03 ### Added - [Feature Preview - alpha] Support for `client.hosted_extractors.sources`. diff --git a/cognite/client/_api/data_modeling/instances.py b/cognite/client/_api/data_modeling/instances.py index ba872aeda6..5cfda08348 100644 --- a/cognite/client/_api/data_modeling/instances.py +++ b/cognite/client/_api/data_modeling/instances.py @@ -973,7 +973,8 @@ def apply( def search( self, view: ViewId, - query: str, + query: str | None = None, + *, instance_type: Literal["node"] = "node", properties: list[str] | None = None, target_units: list[TargetUnit] | None = None, @@ -988,7 +989,8 @@ def search( def search( self, view: ViewId, - query: str, + query: str | None = None, + *, instance_type: Literal["edge"], properties: list[str] | None = None, target_units: list[TargetUnit] | None = None, @@ -1003,7 +1005,8 @@ def search( def search( self, view: ViewId, - query: str, + query: str | None = None, + *, instance_type: type[T_Node], properties: list[str] | None = None, target_units: list[TargetUnit] | None = None, @@ -1018,7 +1021,8 @@ def search( def search( self, view: ViewId, - query: str, + query: str | None = None, + *, instance_type: type[T_Edge], properties: list[str] | None = None, target_units: list[TargetUnit] | None = None, @@ -1032,7 +1036,7 @@ def search( def search( self, view: ViewId, - query: str, + query: str | None = None, instance_type: Literal["node", "edge"] | type[T_Node] | type[T_Edge] = "node", properties: list[str] | None = None, target_units: list[TargetUnit] | None = None, @@ -1046,7 +1050,7 @@ def search( Args: view (ViewId): View to search in. - query (str): Query string that will be parsed and used for search. + query (str | None): Query string that will be parsed and used for search. instance_type (Literal["node", "edge"] | type[T_Node] | type[T_Edge]): Whether to search for nodes or edges. properties (list[str] | None): Optional array of properties you want to search through. If you do not specify one or more properties, the service will search all text fields within the view. target_units (list[TargetUnit] | None): Properties to convert to another unit. The API can only convert to another unit if a unit has been defined as part of the type on the underlying container being queried. @@ -1103,7 +1107,9 @@ def search( else: raise ValueError(f"Invalid instance type: {instance_type}") - body = {"view": view.dump(camel_case=True), "query": query, "instanceType": instance_type_str, "limit": limit} + body: dict[str, Any] = {"view": view.dump(camel_case=True), "instanceType": instance_type_str, "limit": limit} + if query: + body["query"] = query if properties: body["properties"] = properties if include_typing: diff --git a/cognite/client/_version.py b/cognite/client/_version.py index b1cad44260..9180aa7e35 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.58.2" +__version__ = "7.58.3" __api_subversion__ = "20230101" diff --git a/pyproject.toml b/pyproject.toml index 7775497505..7726550e8e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.58.2" +version = "7.58.3" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com"