Skip to content

Commit

Permalink
immutable props (#1821)
Browse files Browse the repository at this point in the history
  • Loading branch information
erlendvollset authored Jun 25, 2024
1 parent c4ef3cd commit e191223
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ runs:
- name: Install dependencies
shell: bash
run: |
pip install --upgrade pip poetry
python -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install --no-interaction --no-ansi ${{ inputs.extras }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ playground.py
scripts/tmp/
my_file.txt
.venv/
*.env
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ Changes are grouped as follows
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [7.52.0] - 2024-06-19
### Added

- Support the `immutable` flag on container/view properties

## [7.51.1] - 2024-06-18
### Fixed
### Added

- Added support for serializing Node/Edge properties of type `list` of `NodeId`and `DirectRelationReference`,
`date`, `datetime` and list of `date` and `datetime` to `json` format.
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.51.1"
__version__ = "7.52.0"
__api_subversion__ = "20230101"
5 changes: 4 additions & 1 deletion cognite/client/data_classes/data_modeling/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class ContainerProperty(CogniteObject):
name: str | None = None
default_value: str | int | float | bool | dict | None = None
description: str | None = None
immutable: bool = False

@classmethod
def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None = None) -> Self:
Expand All @@ -267,12 +268,14 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None =
name=resource.get("name"),
default_value=resource.get("defaultValue"),
description=resource.get("description"),
immutable=resource.get("immutable", False),
)

def dump(self, camel_case: bool = True) -> dict[str, str | dict]:
output: dict[str, str | dict] = {}
output: dict[str, Any] = {}
if self.type:
output["type"] = self.type.dump(camel_case)
output["immutable"] = self.immutable
for key in ["nullable", "auto_increment", "name", "default_value", "description"]:
if (value := getattr(self, key)) is not None:
output[key] = value
Expand Down
2 changes: 2 additions & 0 deletions cognite/client/data_classes/data_modeling/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ class MappedProperty(ViewProperty):
container_property_identifier: str
type: PropertyType
nullable: bool
immutable: bool
auto_increment: bool
source: ViewId | None = None
default_value: str | int | dict | None = None
Expand All @@ -451,6 +452,7 @@ def _load(cls, resource: dict[str, Any], cognite_client: CogniteClient | None =
container_property_identifier=resource["containerPropertyIdentifier"],
type=PropertyType.load({k: v for k, v in type_.items() if k != "source"}),
nullable=resource["nullable"],
immutable=resource["immutable"],
auto_increment=resource["autoIncrement"],
source=ViewId.load(source) if source else None,
default_value=resource.get("defaultValue"),
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.51.1"
version = "7.52.0"
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 @@ -32,11 +32,11 @@ class TestContainerProperty:
@pytest.mark.parametrize(
"data",
[
{"type": {"type": "direct", "list": False}},
{"type": {"type": "direct", "list": False}, "immutable": False},
# List is not required, but gets set and thus will be dumped
{"type": {"type": "int32", "list": False}},
{"type": {"type": "text", "list": False, "collation": "ucs_basic"}},
{"type": {"type": "file", "list": False}},
{"type": {"type": "int32", "list": False}, "immutable": False},
{"type": {"type": "text", "list": False, "collation": "ucs_basic"}, "immutable": False},
{"type": {"type": "file", "list": False}, "immutable": False},
],
)
def test_load_dump__only_required(self, data: dict) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_load_dumped_mapped_property_for_read(self) -> None:
"nullable": False,
"autoIncrement": False,
"defaultValue": None,
"immutable": False,
}
actual = ViewProperty.load(input)
assert isinstance(actual, MappedProperty)
Expand All @@ -50,6 +51,7 @@ def test_load_dumped_mapped_property_for_read(self) -> None:
"description": None,
"name": "fullName",
"nullable": False,
"immutable": False,
"type": {
"type": "direct",
"source": {"external_id": "myExternalId", "space": "mySpace", "version": "myVersion"},
Expand Down

0 comments on commit e191223

Please sign in to comment.