-
Notifications
You must be signed in to change notification settings - Fork 27
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 filter dump in Data Modeling #1510
Changes from 5 commits
98019ac
b1c8289
dc87540
8796ce6
cd704a9
0ba3199
5f5ab9e
cad6dbd
864e1cf
04613f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from __future__ import annotations | ||
|
||
__version__ = "7.0.2" | ||
__version__ = "7.0.3" | ||
__api_subversion__ = "V20220125" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ | |||||
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 | ||||||
|
||||||
|
||||||
@dataclass(frozen=True) | ||||||
|
@@ -169,7 +170,7 @@ def version(self) -> str | None: | |||||
Id = Union[Tuple[str, str], Tuple[str, str, str], IdLike, VersionedIdLike] | ||||||
|
||||||
|
||||||
def _load_space_identifier(ids: str | Sequence[str]) -> DataModelingIdentifierSequence: | ||||||
def _load_space_identifier(ids: str | SequenceNotStr[str]) -> DataModelingIdentifierSequence: | ||||||
is_sequence = isinstance(ids, Sequence) and not isinstance(ids, str) | ||||||
spaces = [ids] if isinstance(ids, str) else ids | ||||||
return DataModelingIdentifierSequence( | ||||||
|
@@ -193,7 +194,7 @@ def create_args(id_: Id) -> tuple[str, str, str | None, Literal["node", "edge"] | |||||
return id_[0], id_[1], None, id_type # type: ignore[return-value] | ||||||
raise ValueError("Instance given as a tuple must have two elements (space, externalId)") | ||||||
if isinstance(id_, tuple): | ||||||
return id_[0], id_[1], id_[2] if len(id_) == 3 else None, None | ||||||
return id_[0], id_[1], (id_[2] if len(id_) == 3 else None), None | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is more readable or not, you choose 😜
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we catch this in a test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nvm i see it's already done 💯) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @erlendvollset That change was only for easier readability (not referring to my suggestion but his added parens) |
||||||
instance_type = None | ||||||
if is_instance: | ||||||
instance_type = "node" if isinstance(id_, NodeId) else "edge" | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,8 +68,20 @@ def _dump_property(property_: PropertyReference, camel_case: bool) -> list[str] | |
class Filter(ABC): | ||
_filter_name: str | ||
|
||
def dump(self, camel_case: bool = True) -> dict[str, Any]: | ||
return {self._filter_name: self._filter_body(camel_case)} | ||
def dump(self, camel_case_property: bool = False) -> dict[str, Any]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the bug introduced in v7, the default was changed from |
||
""" | ||
Dump the filter to a dictionary. | ||
|
||
Args: | ||
camel_case_property (bool): Whether to camel case the property names. Defaults to False. Typically, | ||
when the filter is used in data modeling, the property names should not be changed, | ||
while when used with Assets, Event, Sequences, or Files, the property names should be camel cased. | ||
doctrino marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Returns: | ||
dict[str, Any]: The filter as a dictionary. | ||
|
||
""" | ||
return {self._filter_name: self._filter_body(camel_case_property=camel_case_property)} | ||
|
||
@classmethod | ||
def load(cls, filter_: dict[str, Any]) -> Filter: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh nice! ...to get overloads working 👌