Skip to content

Commit

Permalink
In filter with node ids (#1991)
Browse files Browse the repository at this point in the history
Co-authored-by: Håkon V. Treider <[email protected]>
  • Loading branch information
MortGron and haakonvt authored Nov 2, 2024
1 parent 0941557 commit f8aa382
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 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.

## [7.64.6] - 2024-10-22
### Added
- Data modeling filters now support the use of `NodeId` (and `EdgeId`) directly.

## [7.64.5] - 2024-11-01
### Fixed
- The `client.functions.schedules.create` method no longer mutates the input `FunctionScheduleWrite` object.
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__ = "7.64.5"
__version__ = "7.64.6"
__api_subversion__ = "20230101"
6 changes: 5 additions & 1 deletion cognite/client/data_classes/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from cognite.client.data_classes._base import EnumProperty, Geometry
from cognite.client.data_classes.labels import Label
from cognite.client.utils._identifier import InstanceId
from cognite.client.utils._text import convert_all_keys_to_camel_case, to_camel_case
from cognite.client.utils.useful_types import SequenceNotStr

Expand All @@ -16,7 +17,7 @@

PropertyReference: TypeAlias = str | tuple[str, ...] | list[str] | EnumProperty

RawValue: TypeAlias = str | float | bool | Sequence | Mapping[str, Any] | Label
RawValue: TypeAlias = str | float | bool | Sequence | Mapping[str, Any] | Label | InstanceId


@dataclass
Expand All @@ -42,6 +43,9 @@ def _dump_filter_value(value: FilterValueList | FilterValue) -> Any:
elif isinstance(value, ParameterValue):
return {"parameter": value.parameter}

elif isinstance(value, InstanceId):
return value.dump(include_instance_type=False)

elif hasattr(value, "dump"):
return value.dump()

Expand Down
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 = "7.64.5"
version = "7.64.6"
description = "Cognite Python SDK"
readme = "README.md"
documentation = "https://cognite-sdk-python.readthedocs-hosted.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import cognite.client.data_classes.filters as f
from cognite.client._api.data_modeling.instances import InstancesAPI
from cognite.client.data_classes._base import EnumProperty
from cognite.client.data_classes.data_modeling import ViewId
from cognite.client.data_classes.data_modeling import NodeId, ViewId
from cognite.client.data_classes.data_modeling.data_types import DirectRelationReference
from cognite.client.data_classes.filters import Filter, UnknownFilter
from tests.utils import all_subclasses
Expand Down Expand Up @@ -277,6 +277,19 @@ def dump_filter_test_data() -> Iterator[ParameterSet]:
]
}
yield pytest.param(nested_overloaded_filter, expected, id="Compound filter with nested overloaded and")
in_filter_with_node_id = f.In("name", [NodeId(space="space", external_id="ex_id")])
expected = {
"in": {
"property": ["name"],
"values": [
{
"externalId": "ex_id",
"space": "space",
},
],
},
}
yield pytest.param(in_filter_with_node_id, expected, id="In filter with node ID")


@pytest.mark.parametrize("user_filter, expected", list(dump_filter_test_data()))
Expand Down

0 comments on commit f8aa382

Please sign in to comment.