Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented ReverseDirectRelationConnection #1540

Merged
merged 11 commits into from
Dec 20, 2023
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.7.0] - 2023-12-20
### Added
- Support for `ViewProperty` types `SingleReverseDirectRelation` and `MultiReverseDirectRelation` in data modeling.

## [7.6.0] - 2023-12-13
### Added
- Support for querying data models through graphql. See `client.data_modeling.graphql.query`.
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.6.0"
__version__ = "7.7.0"
__api_subversion__ = "V20220125"
2 changes: 2 additions & 0 deletions cognite/client/data_classes/data_modeling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
DataModelingId,
EdgeId,
NodeId,
PropertyId,
VersionedDataModelingId,
ViewId,
ViewIdentifier,
Expand Down Expand Up @@ -98,6 +99,7 @@
"ViewIdentifier",
"ViewApply",
"ViewApplyList",
"PropertyId",
"MappedPropertyApply",
"VersionedDataModelingId",
"DataModelingId",
Expand Down
35 changes: 34 additions & 1 deletion cognite/client/data_classes/data_modeling/ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

from abc import ABC
from dataclasses import asdict, dataclass, field
from typing import Any, ClassVar, Literal, Protocol, Sequence, Tuple, TypeVar, Union, cast
from typing import TYPE_CHECKING, Any, ClassVar, Literal, Protocol, Sequence, Tuple, TypeVar, Union, cast

from typing_extensions import Self

from cognite.client.data_classes._base import CogniteObject
from cognite.client.utils._auxiliary import rename_and_exclude_keys
from cognite.client.utils._identifier import DataModelingIdentifier, DataModelingIdentifierSequence
from cognite.client.utils._text import convert_all_keys_recursive, convert_all_keys_to_snake_case
from cognite.client.utils.useful_types import SequenceNotStr

if TYPE_CHECKING:
from cognite.client import CogniteClient


@dataclass(frozen=True)
class AbstractDataclass(ABC):
Expand Down Expand Up @@ -138,6 +144,33 @@ def as_property_ref(self, property: str) -> tuple[str, ...]:
return (self.space, self.as_source_identifier(), property)


@dataclass(frozen=True)
class PropertyId(CogniteObject):
source: ViewId | ContainerId
property: str

@classmethod
def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self:
return cls(
source=cls.__load_view_or_container_id(resource["source"]),
property=resource["identifier"],
)

@staticmethod
def __load_view_or_container_id(view_or_container_id: dict[str, Any]) -> ViewId | ContainerId:
if "type" in view_or_container_id and view_or_container_id["type"] in {"view", "container"}:
if view_or_container_id["type"] == "view":
return ViewId.load(view_or_container_id)
return ContainerId.load(view_or_container_id)
raise ValueError(f"Invalid type {view_or_container_id}")

def dump(self, camel_case: bool = True) -> dict[str, Any]:
return {
"source": self.source.dump(camel_case=camel_case, include_type=True),
"identifier": self.property,
}


@dataclass(frozen=True)
class DataModelId(VersionedDataModelingId):
_type = "datamodel"
Expand Down
Loading