Skip to content

Commit

Permalink
Fix HasData filter (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortGron authored Sep 18, 2023
1 parent 34e9eac commit f9c9e5c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 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.2] - 2023-09-12
### Fixed
- Using the `HasData` filter would raise an API error in CDF.

## [6.25.1] - 2023-09-15
### Fixed
- Using nonce credentials now works as expected for `transformations.[create, update]`. Previously, the attempt to create
Expand Down
3 changes: 2 additions & 1 deletion cognite/client/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

__version__ = "6.25.1"
__version__ = "6.25.2"

__api_subversion__ = "V20220125"
25 changes: 19 additions & 6 deletions cognite/client/data_classes/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ def load(cls, filter_: dict[str, Any]) -> Filter:
elif filter_name == MatchAll._filter_name:
return MatchAll()
elif filter_name == HasData._filter_name:
return HasData(containers=filter_body.get("containers"), views=filter_body.get("views"))
containers = []
views = []
for view_or_space in filter_body:
if view_or_space["type"] == "container":
containers.append((view_or_space["space"], view_or_space["externalId"]))
else:
views.append((view_or_space["space"], view_or_space["externalId"], view_or_space.get("version")))
return HasData(containers=containers, views=views)
elif filter_name == Range._filter_name:
return Range(
property=filter_body["property"],
Expand Down Expand Up @@ -283,11 +290,17 @@ def __init__(
self.__containers: list[ContainerId] = [ContainerId.load(container) for container in (containers or [])]
self.__views: list[ViewId] = [ViewId.load(view) for view in (views or [])]

def _filter_body(self, camel_case_property: bool) -> dict:
return {
"views": [view.as_tuple() for view in self.__views],
"containers": [container.as_tuple() for container in self.__containers],
}
def _filter_body(self, camel_case_property: bool) -> list:
views = [v.as_tuple() for v in self.__views]
filter_body_views = [
{"type": "view", "space": space, "externalId": externalId, "version": version}
for space, externalId, version in views
]
containers = [c.as_tuple() for c in self.__containers]
filter_body_containers = [
{"type": "container", "space": space, "externalId": externalId} for space, externalId in containers
]
return filter_body_views + filter_body_containers


@final
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 = "6.25.1"
version = "6.25.2"

description = "Cognite Python SDK"
readme = "README.md"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def load_and_dump_equals_data() -> Iterator[ParameterSet]:
"lte": "2021-01-01T00:00:00Z",
}
},
{"hasData": {"views": [("space", "viewExternalId", "v1")], "containers": []}},
{"hasData": [{"type": "view", "space": "space", "externalId": "viewExternalId", "version": "v1"}]},
]
},
id="And hasData and overlaps",
Expand Down Expand Up @@ -138,7 +138,7 @@ def dump_filter_test_data() -> Iterator[ParameterSet]:
},
{
"or": [
{"hasData": {"views": [], "containers": [("space", "container")]}},
{"hasData": [{"type": "container", "space": "space", "externalId": "container"}]},
{
"overlaps": {
"startProperty": ("space", "container", "prop1"),
Expand Down

0 comments on commit f9c9e5c

Please sign in to comment.