Skip to content

Commit

Permalink
Fix GeoLocation._load raising KeyError("type") (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt authored Oct 17, 2024
1 parent 528ef1c commit f37aa94
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
7 changes: 6 additions & 1 deletion 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.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`.
Expand All @@ -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`
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.5"
__version__ = "7.63.6"
__api_subversion__ = "20230101"
15 changes: 9 additions & 6 deletions cognite/client/data_classes/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cognite/client/data_classes/transformations/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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.63.5"
version = "7.63.6"
description = "Cognite Python SDK"
readme = "README.md"
documentation = "https://cognite-sdk-python.readthedocs-hosted.com"
Expand Down

0 comments on commit f37aa94

Please sign in to comment.