diff --git a/CHANGELOG.cdf-tk.md b/CHANGELOG.cdf-tk.md index aa4f491cc..5653e7909 100644 --- a/CHANGELOG.cdf-tk.md +++ b/CHANGELOG.cdf-tk.md @@ -25,6 +25,8 @@ Changes are grouped as follows: - Running the build command, `cdf-tk build`, with a `View` resource with a `hasData` filter would print a `UnusedParameterWarning: Parameter 'externalId' is not used in section ('filter', 'hasData', 0, 'externalId').`. This is incorrect and is now fixed to not print this warning. +- If you had a `container` with a direct relation property with a required constraint, the `cdf-tk build` command + would incorrectly yield a warning that the `Parameter 'type' is not used ...`. This is now fixed. ## [0.2.0b1] - 2024-05-20 diff --git a/cognite_toolkit/_cdf_tk/loaders/_resource_loaders.py b/cognite_toolkit/_cdf_tk/loaders/_resource_loaders.py index c4b023c42..262e58a5b 100644 --- a/cognite_toolkit/_cdf_tk/loaders/_resource_loaders.py +++ b/cognite_toolkit/_cdf_tk/loaders/_resource_loaders.py @@ -2431,6 +2431,13 @@ def get_write_cls_parameter_spec(cls) -> ParameterSpecSet: is_required=True, _is_nullable=False, ), + ParameterSpec( + # direct relations with constraint + ("properties", ANY_STR, "type", "container", "type"), + frozenset({"str"}), + is_required=True, + _is_nullable=False, + ), ParameterSpec( ("constraints", ANY_STR, "constraintType"), frozenset({"str"}), diff --git a/tests/tests_unit/test_cdf_tk/test_loaders.py b/tests/tests_unit/test_cdf_tk/test_loaders.py index 24cfade0f..b448578df 100644 --- a/tests/tests_unit/test_cdf_tk/test_loaders.py +++ b/tests/tests_unit/test_cdf_tk/test_loaders.py @@ -146,6 +146,39 @@ def test_upsert_data_set(self, cognite_client_approval: ApprovalCogniteClient): assert len(unchanged) == 1 +class TestContainerLoader: + @pytest.mark.parametrize( + "item", + [ + pytest.param( + { + "properties": { + "myDirectRelation": { + "name": "my direct relation", + "type": { + "type": "direct", + "container": { + "type": "container", + "space": "sp_my_space", + "externalId": "my_container", + }, + }, + } + } + }, + id="Direct relation property with require constraint.", + ), + ], + ) + def test_valid_spec(self, item: dict): + spec = ContainerLoader.get_write_cls_parameter_spec() + dumped = read_parameters_from_dict(item) + + extra = dumped - spec + + assert not extra, f"Extra keys: {extra}" + + class TestViewLoader: @pytest.mark.parametrize( "item",