Skip to content

Commit

Permalink
cherry pick
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino committed Sep 13, 2024
1 parent f4d8eff commit de230a0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,4 @@ cognite_toolkit/config.local.yaml
build.*
cognite_toolkit/.env.*
module_upgrade/project_inits
function_local_venvs/
6 changes: 6 additions & 0 deletions CHANGELOG.cdf-tk.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Changes are grouped as follows:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [0.2.21] - 2024-09-13

### Fixed

- Groups without metadata no longer triggers redeploy when running `cdf deploy`

## [0.2.20] - 2024-08-31

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ def _are_equal(
local_dumped = local.dump()
cdf_dumped = cdf_resource.as_write().dump()

# Remove metadata if it is empty to avoid false negatives
# as a result of cdf_resource.metadata = {} != local.metadata = None
if not local_dumped.get("metadata"):
local_dumped.pop("metadata", None)
if not cdf_dumped.get("metadata"):
cdf_dumped.pop("metadata", None)

scope_names = ["datasetScope", "idScope", "extractionPipelineScope"]

ids_by_acl_by_actions_by_scope: dict[str, dict[frozenset[str], dict[str, list[str]]]] = {}
Expand Down
44 changes: 43 additions & 1 deletion tests/test_unit/test_cdf_tk/test_loaders/test_group_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from _pytest.monkeypatch import MonkeyPatch
from cognite.client.data_classes import Group, GroupWrite
from cognite.client.data_classes import Group, GroupWrite, GroupWriteList

from cognite_toolkit._cdf_tk.commands import DeployCommand
from cognite_toolkit._cdf_tk.loaders import (
Expand Down Expand Up @@ -201,3 +201,45 @@ def test_get_dependent_items(self, item: dict, expected: list[tuple[type[Resourc
actual_dependent_items = GroupLoader.get_dependent_items(item)

assert list(actual_dependent_items) == expected

def test_unchanged_new_group_without_metadata(
self, cdf_tool_config: CDFToolConfig, cognite_client_approval: ApprovalCogniteClient, monkeypatch: MonkeyPatch
) -> None:
loader = GroupResourceScopedLoader.create_loader(cdf_tool_config, None)
local_group = GroupWrite.load("""name: gp_no_metadata
sourceId: 123
capabilities:
- assetsAcl:
actions:
- READ
scope:
all: {}
""")
cdf_group = Group.load("""name: gp_no_metadata
sourceId: 123
capabilities:
- assetsAcl:
actions:
- READ
scope:
all: {}
metadata: {}
id: 3760258445038144
isDeleted: false
deletedTime: -1
""")

# Simulate that one group is is already in CDF
cognite_client_approval.append(
Group,
[cdf_group],
)
cmd = DeployCommand(print_warning=False)
to_create, to_change, unchanged = cmd.to_create_changed_unchanged_triple(
GroupWriteList([local_group]),
loader,
)

assert len(to_create) == 0
assert len(to_change) == 0
assert len(unchanged) == 1

0 comments on commit de230a0

Please sign in to comment.