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 filter dump in Data Modeling #1510

Merged
merged 10 commits into from
Nov 15, 2023
Merged

Fix filter dump in Data Modeling #1510

merged 10 commits into from
Nov 15, 2023

Conversation

doctrino
Copy link
Contributor

@doctrino doctrino commented Nov 15, 2023

Description

[7.0.3] - 2023-11-15

Fixed

  • Bug when cognite.client.data_classes.filter used with any data_modeling endpoint raised a CogniteAPIError for
    snake_cased properties. This is now fixed.

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • Changelog updated in CHANGELOG.md.
  • Version bumped. If triggering a new release is desired, bump the version number in _version.py and pyproject.toml per semantic versioning.

@doctrino doctrino requested review from a team as code owners November 15, 2023 15:30
@@ -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]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the bug introduced in v7, the default was changed from False to True

Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Merging #1510 (04613f3) into master (d5286ae) will increase coverage by 0.02%.
The diff coverage is 87.50%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1510      +/-   ##
==========================================
+ Coverage   91.62%   91.64%   +0.02%     
==========================================
  Files         120      120              
  Lines       15605    15607       +2     
==========================================
+ Hits        14298    14303       +5     
+ Misses       1307     1304       -3     
Files Coverage Δ
cognite/client/_api/assets.py 95.01% <ø> (ø)
cognite/client/_api/data_modeling/spaces.py 85.71% <100.00%> (+0.34%) ⬆️
cognite/client/_api/events.py 92.94% <ø> (ø)
cognite/client/_api/sequences.py 91.94% <ø> (ø)
cognite/client/_api/time_series.py 93.33% <ø> (ø)
cognite/client/_api_client.py 89.52% <ø> (ø)
cognite/client/_version.py 100.00% <100.00%> (ø)
cognite/client/data_classes/data_modeling/ids.py 91.48% <100.00%> (+0.06%) ⬆️
cognite/client/data_classes/filters.py 98.07% <100.00%> (ø)
cognite/client/data_classes/relationships.py 90.97% <100.00%> (ø)
... and 1 more

... and 1 file with indirect coverage changes

Copy link
Contributor

@haakonvt haakonvt left a comment

Choose a reason for hiding this comment

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

I like the change to camel_case_property to make it distinct from other methods

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
return id_[0], id_[1], (id_[2] if len(id_) == 3 else None), None
return (*id_, None, None)[:4]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we catch this in a test?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(nvm i see it's already done 💯)

Copy link
Contributor

@haakonvt haakonvt Nov 15, 2023

Choose a reason for hiding this comment

The 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)

if instance.target is not None:
instance.target = instance._convert_resource(instance.target, instance.target_type) # type: ignore
instance.target = instance._convert_resource(instance.target, instance.target_type, cognite_client) # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch!

@@ -63,18 +64,18 @@ def __iter__(self) -> Iterator[Space]:
return self()

@overload
def retrieve(self, spaces: str) -> Space | None: # type: ignore[overload-overlap]
def retrieve(self, spaces: str) -> Space | None:
Copy link
Contributor

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 👌

cognite/client/data_classes/filters.py Outdated Show resolved Hide resolved
@doctrino doctrino merged commit 1932572 into master Nov 15, 2023
7 checks passed
@doctrino doctrino deleted the fix-filter-dump branch November 15, 2023 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants