From f37aa9471bd6f13e3bd6bfaf76627d3066b0f3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20V=2E=20Treider?= Date: Thu, 17 Oct 2024 15:37:47 +0200 Subject: [PATCH] Fix `GeoLocation._load` raising `KeyError("type")` (#1981) --- CHANGELOG.md | 7 ++++++- cognite/client/_version.py | 2 +- cognite/client/data_classes/shared.py | 15 +++++++++------ .../client/data_classes/transformations/common.py | 2 +- pyproject.toml | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4d5a92507..5b922ef976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,11 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [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 + now load as UnknownCogniteObject, rather than throwing an exception (typically `KeyError`). + ## [7.63.5] - 2024-10-15 ### Fixed - Added missing parameter `notification_config` to `ExtractionPipeline`. @@ -31,7 +36,7 @@ Changes are grouped as follows - NodeList and EdgeList (and subclasses) now support using `.get` with an `external_id` as a shortcut over using `instance_id`. When the `external_id` is ambiguous (non-unique, multiple spaces), a ValueError is raised. Thus, using `external_id` is no longer deprecated. - + ## [7.63.2] - 2024-10-11 ### Fixed - Setting up interactive `OAuthInteractive` sessions no longer raises `TypeError` as the lower bound for the `msal` diff --git a/cognite/client/_version.py b/cognite/client/_version.py index 8f5ae4f0f9..0a7cc03f1a 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.63.5" +__version__ = "7.63.6" __api_subversion__ = "20230101" diff --git a/cognite/client/data_classes/shared.py b/cognite/client/data_classes/shared.py index 1bf268e29a..3f73a3b5ea 100644 --- a/cognite/client/data_classes/shared.py +++ b/cognite/client/data_classes/shared.py @@ -5,7 +5,7 @@ from typing_extensions import Self -from cognite.client.data_classes._base import CogniteFilter, CogniteObject, Geometry +from cognite.client.data_classes._base import CogniteFilter, CogniteObject, Geometry, UnknownCogniteObject if TYPE_CHECKING: from cognite.client import CogniteClient @@ -144,11 +144,14 @@ def __init__(self, type: Literal["Feature"], geometry: Geometry, properties: dic @classmethod def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> GeoLocation: - return cls( - type=resource["type"], - geometry=Geometry._load(resource["geometry"], cognite_client), - properties=resource.get("properties"), - ) + if "type" in resource: + return cls( + type=resource["type"], + geometry=Geometry._load(resource["geometry"], cognite_client), + properties=resource.get("properties"), + ) + # Years ago, the API didn't enforce the current restriction on the type field: + return UnknownCogniteObject(resource) # type: ignore[return-value] def dump(self, camel_case: bool = True) -> dict[str, Any]: result = super().dump(camel_case) diff --git a/cognite/client/data_classes/transformations/common.py b/cognite/client/data_classes/transformations/common.py index e53bf15339..046de2f97f 100644 --- a/cognite/client/data_classes/transformations/common.py +++ b/cognite/client/data_classes/transformations/common.py @@ -163,7 +163,7 @@ def instances(data_model: DataModelInfo | None = None, instance_space: str | Non def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> TransformationDestination: type_ = resource.get("type") if type_ is None: - return UnknownCogniteObject._load(resource) # type: ignore[return-value] + return UnknownCogniteObject(resource) # type: ignore[return-value] if type_ == "raw": return RawTable._load(resource) diff --git a/pyproject.toml b/pyproject.toml index 396ec6c02c..32d8b16074 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.63.5" +version = "7.63.6" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com"