From de230a0ce3625150b8ba1665ec274dc6aa805acc Mon Sep 17 00:00:00 2001 From: anders-albert Date: Fri, 13 Sep 2024 09:12:44 +0200 Subject: [PATCH 1/3] cherry pick --- .gitignore | 1 + CHANGELOG.cdf-tk.md | 6 +++ .../loaders/_resource_loaders/auth_loaders.py | 7 +++ .../test_loaders/test_group_loader.py | 44 ++++++++++++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0b7eb8270..bce69ac0b 100644 --- a/.gitignore +++ b/.gitignore @@ -294,3 +294,4 @@ cognite_toolkit/config.local.yaml build.* cognite_toolkit/.env.* module_upgrade/project_inits +function_local_venvs/ diff --git a/CHANGELOG.cdf-tk.md b/CHANGELOG.cdf-tk.md index 102ba7257..3b621fc5f 100644 --- a/CHANGELOG.cdf-tk.md +++ b/CHANGELOG.cdf-tk.md @@ -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 diff --git a/cognite_toolkit/_cdf_tk/loaders/_resource_loaders/auth_loaders.py b/cognite_toolkit/_cdf_tk/loaders/_resource_loaders/auth_loaders.py index 5c4a04b9a..f475061ec 100644 --- a/cognite_toolkit/_cdf_tk/loaders/_resource_loaders/auth_loaders.py +++ b/cognite_toolkit/_cdf_tk/loaders/_resource_loaders/auth_loaders.py @@ -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]]]] = {} diff --git a/tests/test_unit/test_cdf_tk/test_loaders/test_group_loader.py b/tests/test_unit/test_cdf_tk/test_loaders/test_group_loader.py index ba8c85bda..242a20f74 100644 --- a/tests/test_unit/test_cdf_tk/test_loaders/test_group_loader.py +++ b/tests/test_unit/test_cdf_tk/test_loaders/test_group_loader.py @@ -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 ( @@ -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 From 97f3f94f0f93998508890ba80f2cc99ca0b197c1 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Fri, 13 Sep 2024 09:13:32 +0200 Subject: [PATCH 2/3] build: changelog --- CHANGELOG.templates.md | 4 ++++ cognite_toolkit/_system.yaml | 2 +- cognite_toolkit/_version.py | 2 +- pyproject.toml | 2 +- tests/data/build_core_model/_build_environment.yaml | 2 +- .../data/build_group_with_unknown_acl/_build_environment.yaml | 2 +- tests/data/project_for_test/_system.yaml | 2 +- tests/data/project_no_cognite_modules/_system.yaml | 2 +- tests/data/project_with_bad_modules/_system.yaml | 2 +- tests/data/run_data/_system.yaml | 2 +- 10 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.templates.md b/CHANGELOG.templates.md index 90a3daaf1..071987537 100644 --- a/CHANGELOG.templates.md +++ b/CHANGELOG.templates.md @@ -15,6 +15,10 @@ Changes are grouped as follows: - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [0.2.21] - 2024-09-13 + +No changes to templates. + ## [0.2.20] - 2024-08-31 ## Fixed diff --git a/cognite_toolkit/_system.yaml b/cognite_toolkit/_system.yaml index c0a8e6330..1c220b6a5 100644 --- a/cognite_toolkit/_system.yaml +++ b/cognite_toolkit/_system.yaml @@ -25,4 +25,4 @@ packages: - example_pump_data_model # This part is used by cdf-toolkit to keep track of the version and help you upgrade. -cdf_toolkit_version: 0.2.20 \ No newline at end of file +cdf_toolkit_version: 0.2.21 \ No newline at end of file diff --git a/cognite_toolkit/_version.py b/cognite_toolkit/_version.py index 943c601c0..4c38b9247 100644 --- a/cognite_toolkit/_version.py +++ b/cognite_toolkit/_version.py @@ -1 +1 @@ -__version__ = "0.2.20" +__version__ = "0.2.21" diff --git a/pyproject.toml b/pyproject.toml index 7a4cbf288..033f0ed5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cognite_toolkit" -version = "0.2.20" +version = "0.2.21" description = "Official Cognite Data Fusion tool for project templates and configuration deployment" authors = ["Cognite AS "] license = "Apache-2" diff --git a/tests/data/build_core_model/_build_environment.yaml b/tests/data/build_core_model/_build_environment.yaml index 6917f0d7a..45e0b8371 100644 --- a/tests/data/build_core_model/_build_environment.yaml +++ b/tests/data/build_core_model/_build_environment.yaml @@ -4,4 +4,4 @@ project: project-loader-dev type: dev selected: - modules -cdf_toolkit_version: 0.2.20 +cdf_toolkit_version: 0.2.21 diff --git a/tests/data/build_group_with_unknown_acl/_build_environment.yaml b/tests/data/build_group_with_unknown_acl/_build_environment.yaml index 57ab0df26..82e0a85a1 100644 --- a/tests/data/build_group_with_unknown_acl/_build_environment.yaml +++ b/tests/data/build_group_with_unknown_acl/_build_environment.yaml @@ -4,4 +4,4 @@ project: pytest-project type: dev selected: - modules -cdf_toolkit_version: 0.2.20 +cdf_toolkit_version: 0.2.21 diff --git a/tests/data/project_for_test/_system.yaml b/tests/data/project_for_test/_system.yaml index 4de881dc7..b74721894 100644 --- a/tests/data/project_for_test/_system.yaml +++ b/tests/data/project_for_test/_system.yaml @@ -4,4 +4,4 @@ packages: - child_module # This part is used by cdf-toolkit to keep track of the version and help you upgrade. -cdf_toolkit_version: 0.2.20 +cdf_toolkit_version: 0.2.21 diff --git a/tests/data/project_no_cognite_modules/_system.yaml b/tests/data/project_no_cognite_modules/_system.yaml index 2535ded6f..ca3fb4722 100644 --- a/tests/data/project_no_cognite_modules/_system.yaml +++ b/tests/data/project_no_cognite_modules/_system.yaml @@ -3,4 +3,4 @@ packages: {} # This part is used by cdf-toolkit to keep track of the version and help you upgrade. -cdf_toolkit_version: 0.2.20 +cdf_toolkit_version: 0.2.21 diff --git a/tests/data/project_with_bad_modules/_system.yaml b/tests/data/project_with_bad_modules/_system.yaml index 2535ded6f..ca3fb4722 100644 --- a/tests/data/project_with_bad_modules/_system.yaml +++ b/tests/data/project_with_bad_modules/_system.yaml @@ -3,4 +3,4 @@ packages: {} # This part is used by cdf-toolkit to keep track of the version and help you upgrade. -cdf_toolkit_version: 0.2.20 +cdf_toolkit_version: 0.2.21 diff --git a/tests/data/run_data/_system.yaml b/tests/data/run_data/_system.yaml index 1237f1b2b..9fca0f60f 100644 --- a/tests/data/run_data/_system.yaml +++ b/tests/data/run_data/_system.yaml @@ -25,4 +25,4 @@ packages: - example_pump_data_model # This part is used by cdf-toolkit to keep track of the version and help you upgrade. -cdf_toolkit_version: 0.2.20 +cdf_toolkit_version: 0.2.21 From 9b69cb95e49fadb7aa3ca4f96f1aa87d1fb0f574 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Fri, 13 Sep 2024 09:19:25 +0200 Subject: [PATCH 3/3] refactor; missing entry --- cognite_toolkit/_cdf_tk/_migration.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cognite_toolkit/_cdf_tk/_migration.yaml b/cognite_toolkit/_cdf_tk/_migration.yaml index 7f5ddfde6..bf7359778 100644 --- a/cognite_toolkit/_cdf_tk/_migration.yaml +++ b/cognite_toolkit/_cdf_tk/_migration.yaml @@ -1,8 +1,13 @@ -- version: 0.2.20 +- version: 0.2.21 cognite_modules: {} resources: {} tool: {} cognite_modules_hash: "" +- version: 0.2.20 + cognite_modules: {} + resources: {} + tool: {} + cognite_modules_hash: "6be0297c3e6f0097fb53653095b57c9d8d56ca840282199b68c721868ab8131c" - version: 0.2.19 cognite_modules: {} resources: {}