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

fix: instance type not possible to reset to null #1970

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.62.9] - 2024-10-10
### Fixed
- Resetting the type of a node to null, now works as expected when `type=None` is passed.

## [7.62.8] - 2024-10-07
### Added
- [Feature Preview - alpha] Support for `PostgresGateway` `Users` `client.postegres_gateway.users`.
Expand Down
3 changes: 3 additions & 0 deletions cognite/client/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# Max JavaScript-safe integer 2^53 - 1
MAX_VALID_INTERNAL_ID = 9007199254740991
DATA_MODELING_DEFAULT_LIMIT_READ = 10
# Some objects need to differentiate between a default value, typically None and 'parameter no given'
# for which we use this NOT_SET object:
NOT_SET = object()

try:
import numpy as np # noqa F401
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.62.8"
__version__ = "7.62.9"
__api_subversion__ = "20230101"
61 changes: 31 additions & 30 deletions cognite/client/data_classes/data_modeling/cdm/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime
from typing import Literal

from cognite.client._constants import NOT_SET
from cognite.client.data_classes.data_modeling import DirectRelationReference
from cognite.client.data_classes.data_modeling.ids import ViewId
from cognite.client.data_classes.data_modeling.instances import (
Expand Down Expand Up @@ -87,7 +88,7 @@ def __init__(
station_360: DirectRelationReference | tuple[str, str] | None = None,
taken_at: datetime | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
Copy link
Collaborator

@erlendvollset erlendvollset Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, NOT_SET should be an instance of a NotSet class (or I prefer OMITTED/Omitted), and then we do this instead:

Suggested change
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
type: DirectRelationReference | tuple[str, str] | Omitted | None = OMITTED,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While class Omitted with a (singleton instance) OMITTED is nicer for sure! ...I don't really like to expose this to the users (more than necessary, the default value).

It exposes internal details; users will see Omitted in the type annotation and perhaps wonder what it does, when in reality it is an implementation detail. This may lead to unnecessary confusion (do I need to know what this is/does?), which in turn may lead to unintended usage.

It also goes against the principle of what the type annotations mean; these are the allowed types you may pass. The point with the default value is when it is not passed.

) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.translation_x = translation_x
Expand Down Expand Up @@ -263,7 +264,7 @@ def __init__(
revision_type: Literal["CAD", "Image360", "PointCloud"] | None = None,
model_3d: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -385,7 +386,7 @@ def __init__(
model_type: Literal["CAD", "Image360", "PointCloud"] | None = None,
thumbnail: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -495,7 +496,7 @@ def __init__(
aliases: list[str] | None = None,
group_type: Literal["Station360"] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -602,7 +603,7 @@ def __init__(
model_type: Literal["CAD", "Image360", "PointCloud"] | None = None,
thumbnail: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -727,7 +728,7 @@ def __init__(
z_min: float | None = None,
z_max: float | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -857,7 +858,7 @@ def __init__(
revision_type: Literal["CAD", "Image360", "PointCloud"] | None = None,
model_3d: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.status = status
Expand Down Expand Up @@ -975,7 +976,7 @@ def __init__(
scale_y: float | None = None,
scale_z: float | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.translation_x = translation_x
Expand Down Expand Up @@ -1137,7 +1138,7 @@ def __init__(
equipment: list[DirectRelationReference | tuple[str, str]] | None = None,
time_series: list[DirectRelationReference | tuple[str, str]] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -1340,7 +1341,7 @@ def __init__(
asset_class: DirectRelationReference | tuple[str, str] | None = None,
asset_type: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.object_3d = DirectRelationReference.load(object_3d) if object_3d else None
Expand Down Expand Up @@ -1504,7 +1505,7 @@ def __init__(
code: str | None = None,
standard: str | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -1618,7 +1619,7 @@ def __init__(
standard: str | None = None,
asset_class: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -1735,7 +1736,7 @@ def __init__(
model_type: Literal["CAD", "Image360", "PointCloud"] | None = None,
thumbnail: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -1859,7 +1860,7 @@ def __init__(
tree_indexes: list[int] | None = None,
sub_tree_sizes: list[int] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -1990,7 +1991,7 @@ def __init__(
model_3d: DirectRelationReference | tuple[str, str] | None = None,
revision_id: int | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.status = status
Expand Down Expand Up @@ -2095,7 +2096,7 @@ def __init__(
top: DirectRelationReference | tuple[str, str] | None = None,
bottom: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.front = DirectRelationReference.load(front) if front else None
Expand Down Expand Up @@ -2203,7 +2204,7 @@ def __init__(
tags: list[str] | None = None,
aliases: list[str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -2333,7 +2334,7 @@ def __init__(
equipment_type: DirectRelationReference | tuple[str, str] | None = None,
files: list[DirectRelationReference | tuple[str, str]] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -2500,7 +2501,7 @@ def __init__(
standard: str | None = None,
standard_reference: str | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -2648,7 +2649,7 @@ def __init__(
directory: str | None = None,
category: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -2813,7 +2814,7 @@ def __init__(
standard: str | None = None,
standard_reference: str | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.code = code
Expand Down Expand Up @@ -2930,7 +2931,7 @@ def __init__(
model_type: Literal["CAD", "Image360", "PointCloud"] | None = None,
thumbnail: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -3042,7 +3043,7 @@ def __init__(
model_3d: DirectRelationReference | tuple[str, str] | None = None,
revision_id: int | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.status = status
Expand Down Expand Up @@ -3163,7 +3164,7 @@ def __init__(
volume: list[float] | None = None,
format_version: str | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -3299,7 +3300,7 @@ def __init__(
scheduled_start_time: datetime | None = None,
scheduled_end_time: datetime | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.start_time = start_time
Expand Down Expand Up @@ -3401,7 +3402,7 @@ def __init__(
source_system_version: str | None = None,
manufacturer: str | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -3519,7 +3520,7 @@ def __init__(
source_created_user: str | None = None,
source_updated_user: str | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.source_id = source_id
Expand Down Expand Up @@ -3665,7 +3666,7 @@ def __init__(
assets: list[DirectRelationReference | tuple[str, str]] | None = None,
equipment: list[DirectRelationReference | tuple[str, str]] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.is_step = is_step
Expand Down Expand Up @@ -3836,7 +3837,7 @@ def __init__(
source: str | None = None,
source_reference: str | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.name = name
Expand Down Expand Up @@ -3948,7 +3949,7 @@ def __init__(
*,
object_3d: DirectRelationReference | tuple[str, str] | None = None,
existing_version: int | None = None,
type: DirectRelationReference | tuple[str, str] | None = None,
type: DirectRelationReference | tuple[str, str] | None = NOT_SET, # type: ignore [assignment]
) -> None:
TypedNodeApply.__init__(self, space, external_id, existing_version, type)
self.object_3d = DirectRelationReference.load(object_3d) if object_3d else None
Expand Down
Loading