Skip to content

Commit

Permalink
[CDF-22958] Instance iterator bug (#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino authored Oct 21, 2024
1 parent c9e4e85 commit a97a496
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [7.63.7] - 2024-10-18
### Fixed
- Calling `cognite_client.data_modeling.instances(..., chunk_size=False, include_typing=False)` no longer raises a
`TypeError`.

## [7.63.6] - 2024-10-17
### Fixed
- Files, or other resources with geo.location data, created long ago before the current API restriction(s) were in-place
Expand Down
10 changes: 5 additions & 5 deletions cognite/client/_api/data_modeling/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ def __call__(
)

if instance_type == "node":
resource_cls: type = _NodeOrEdgeResourceAdapter
resource_cls: type = Node
list_cls: type = NodeList
elif instance_type == "edge":
resource_cls, list_cls = _NodeOrEdgeResourceAdapter, EdgeList
resource_cls, list_cls = Edge, EdgeList
else:
raise ValueError(f"Invalid instance type: {instance_type}")
if not include_typing:
Expand Down Expand Up @@ -1564,12 +1564,12 @@ def list(
)

if instance_type == "node":
resource_cls: type = _NodeOrEdgeResourceAdapter
resource_cls: type = Node
list_cls: type = NodeList
elif instance_type == "edge":
resource_cls, list_cls = _NodeOrEdgeResourceAdapter, EdgeList
resource_cls, list_cls = Edge, EdgeList
elif inspect.isclass(instance_type) and issubclass(instance_type, TypedNode):
resource_cls = _NodeOrEdgeResourceAdapter
resource_cls = _NodeOrEdgeResourceAdapter(instance_type, Edge) # type: ignore[assignment]
list_cls = _TypedNodeOrEdgeListAdapter(instance_type) # type: ignore[assignment]
elif inspect.isclass(instance_type) and issubclass(instance_type, TypedEdge):
resource_cls = _NodeOrEdgeResourceAdapter(Node, instance_type) # type: ignore[assignment]
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.63.6"
__version__ = "7.63.7"
__api_subversion__ = "20230101"
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.63.6"
version = "7.63.7"
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 @@ -907,6 +907,13 @@ def test_list_in_units(
assert type_.unit is not None
assert type_.unit.external_id == "pressure:pa"

@pytest.mark.usefixtures("node_with_1_1_pressure_in_bar")
def test_iterate_one_by_one(self, cognite_client: CogniteClient, unit_view: View) -> None:
is_source = filters.HasData(views=[unit_view.as_id()])
iterator = cognite_client.data_modeling.instances(filter=is_source, instance_type="node")
first_iter = next(iterator)
assert isinstance(first_iter, Node)

def test_iterate_in_units(
self, cognite_client: CogniteClient, node_with_1_1_pressure_in_bar: NodeApply, unit_view: View
) -> None:
Expand Down

0 comments on commit a97a496

Please sign in to comment.