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

Fixes SDK error on save after include (cherrypick #4123) #4142

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python_sdk/infrahub_sdk/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def __init__(
super().__init__(name=name, schema=schema, branch=branch)

self.initialized = data is not None
self._has_update = data is not None
self._has_update = False

if data is None:
return
Expand Down Expand Up @@ -574,7 +574,7 @@ def __init__(
super().__init__(name=name, schema=schema, branch=branch)

self.initialized = data is not None
self._has_update = data is not None
self._has_update = False

if data is None:
return
Expand Down
45 changes: 42 additions & 3 deletions python_sdk/tests/unit/sdk/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,9 @@ async def test_create_input_data_with_relationships_03(clients, rfile_schema, cl


@pytest.mark.parametrize("client_type", client_types)
async def test_create_input_data_with_relationships_03_for_update(clients, rfile_schema, client_type):
async def test_create_input_data_with_relationships_03_for_update_include_unmodified(
clients, rfile_schema, client_type
):
data = {
"name": {"value": "rfile01", "is_protected": True, "source": "ffffffff"},
"template_path": {"value": "mytemplate.j2"},
Expand All @@ -1088,8 +1090,13 @@ async def test_create_input_data_with_relationships_03_for_update(clients, rfile
node = InfrahubNodeSync(client=clients.sync, schema=rfile_schema, data=data)

node.template_path.value = "my-changed-template.j2"
assert node._generate_input_data(exclude_unmodified=True)["data"] == {
assert node._generate_input_data(exclude_unmodified=False)["data"] == {
"data": {
"name": {
"is_protected": True,
"source": "ffffffff",
"value": "rfile01",
},
"query": {
"id": "qqqqqqqq",
"_relation__is_protected": True,
Expand All @@ -1103,6 +1110,38 @@ async def test_create_input_data_with_relationships_03_for_update(clients, rfile
}


@pytest.mark.parametrize("client_type", client_types)
async def test_create_input_data_with_relationships_03_for_update_exclude_unmodified(
clients, rfile_schema, client_type
):
data = {
"name": {"value": "rfile01", "is_protected": True, "source": "ffffffff"},
"template_path": {"value": "mytemplate.j2"},
"query": {"id": "qqqqqqqq", "source": "ffffffff", "owner": "ffffffff", "is_protected": True},
"repository": {"id": "rrrrrrrr", "source": "ffffffff", "owner": "ffffffff"},
"tags": [{"id": "t1t1t1t1"}, "t2t2t2t2"],
}

if client_type == "standard":
node = InfrahubNode(client=clients.standard, schema=rfile_schema, data=data)
else:
node = InfrahubNodeSync(client=clients.sync, schema=rfile_schema, data=data)

node.template_path.value = "my-changed-template.j2"
assert node._generate_input_data(exclude_unmodified=True)["data"] == {
"data": {
"query": {
"id": "qqqqqqqq",
"_relation__is_protected": True,
"_relation__owner": "ffffffff",
"_relation__source": "ffffffff",
},
"template_path": {"value": "my-changed-template.j2"},
"repository": {"id": "rrrrrrrr", "_relation__owner": "ffffffff", "_relation__source": "ffffffff"},
}
}


@pytest.mark.parametrize("client_type", client_types)
async def test_create_input_data_with_IPHost_attribute(client, ipaddress_schema, client_type):
data = {"address": {"value": ipaddress.ip_interface("1.1.1.1/24"), "is_protected": True}}
Expand Down Expand Up @@ -1426,7 +1465,7 @@ async def test_relationships_excluded_input_data(client, location_schema, client
else:
node = InfrahubNodeSync(client=client, schema=location_schema, data=data)

assert node.tags.has_update is True
assert node.tags.has_update is False


@pytest.mark.parametrize("client_type", client_types)
Expand Down
Loading