-
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
[DOGE-15] Update Sequence Issue #2057
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2057 +/- ##
==========================================
- Coverage 90.50% 90.49% -0.01%
==========================================
Files 141 141
Lines 22493 22533 +40
==========================================
+ Hits 20357 20392 +35
- Misses 2136 2141 +5
|
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.
Great that you are addressing this one! We should decide on how we want to solve the general problem of not-updateable-fields for write-classes in general. Have you done some thinking around this in light of this PR?
# String is not recognized as hashable by mypy | ||
cdf_item_by_id=cdf_item_by_id, # type: ignore[arg-type] |
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.
Why not just use dict[str, T_WritableCogniteResource]
?
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.
Not all identifiers are string. Workflow and data modeling are two examples that uses frozen dataclasses.
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.
Oh right, makes sense. Then you must use Mapping/MutableMapping which is covariant (dict
is invariant)
cognite/client/_api/sequences.py
Outdated
if to_remove := (set(cdf_columns_by_external_id.keys()) - set(columns_by_external_id.keys())): | ||
update_obj["update"]["columns"]["remove"] = list(to_remove) | ||
if to_add := (set(columns_by_external_id.keys()) - set(cdf_columns_by_external_id.keys())): | ||
update_obj["update"]["columns"]["add"] = [columns_by_external_id[ext_id].dump() for ext_id in to_add] | ||
if to_modify := (set(columns_by_external_id.keys()) & set(cdf_columns_by_external_id.keys())): |
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.
This doesn't seem to distinguish based on mode
("replace_ignore_null", "patch", "replace"
)?
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.
You are right, good catch. Since columns are not nullable, I think replace
and 'replace_ignore_null' should be the same behavior. While patch should not do the remove.
cognite/client/_api/sequences.py
Outdated
@@ -730,7 +730,7 @@ def _convert_resource_to_patch_object( | |||
cdf_item_by_id: dict[str, Sequence] | None = None, # type: ignore[override] | |||
) -> dict[str, dict[str, dict]]: | |||
update_obj = super()._convert_resource_to_patch_object(resource, update_attributes, mode) | |||
if not isinstance(resource, SequenceWrite): | |||
if not isinstance(resource, SequenceWrite) or not resource.columns: |
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.
...but if mode=="replace"
, empty columns should mean remove, right?
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.
Good point, but columns are required, so will just remove the check. So you cannot set them to null.
There's still this question left from initial review:
|
I consider that a separate topic apart from this PR. It is on my list of todos, but cannot be solved in this one. |
This PR breaks the example given in the docstring for
|
Maybe, when I think about it, upsert should actually enforce that |
Agreed. |
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.
LGTM!
Description
Please describe the change you have made.
Checklist:
If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.