1+ from __future__ import annotations
2+
13import inspect
24import ipaddress
35from typing import TYPE_CHECKING
1618)
1719from infrahub_sdk .node .constants import SAFE_VALUE
1820from infrahub_sdk .node .related_node import RelatedNode , RelatedNodeSync
19- from infrahub_sdk .schema import GenericSchema , NodeSchemaAPI
20- from tests .unit .sdk .conftest import BothClients
2121
2222if TYPE_CHECKING :
23+ from pytest_httpx import HTTPXMock
24+
2325 from infrahub_sdk .client import InfrahubClient , InfrahubClientSync
26+ from infrahub_sdk .schema import GenericSchema , NodeSchemaAPI
27+
28+ from .conftest import BothClients
2429
2530# type: ignore[attr-defined]
2631
@@ -1366,7 +1371,6 @@ async def test_create_input_data(client, location_schema: NodeSchemaAPI, client_
13661371 "name" : {"value" : "JFK1" },
13671372 "description" : {"value" : "JFK Airport" },
13681373 "type" : {"value" : "SITE" },
1369- "primary_tag" : None ,
13701374 }
13711375 }
13721376
@@ -1394,6 +1398,38 @@ async def test_create_input_data_with_dropdown(client, location_schema_with_drop
13941398 "description" : {"value" : "JFK Airport" },
13951399 "type" : {"value" : "SITE" },
13961400 "status" : {"value" : None },
1401+ }
1402+ }
1403+
1404+
1405+ @pytest .mark .parametrize ("client_type" , client_types )
1406+ async def test_update_input_data_existing_node_with_optional_relationship (
1407+ clients : BothClients , location_schema : NodeSchemaAPI , client_type : str
1408+ ) -> None :
1409+ """Validate that existing nodes include None for uninitialized optional relationships.
1410+
1411+ This ensures that we can explicitly clear optional relationships when updating existing nodes.
1412+ """
1413+ # Simulate an existing node by including an id
1414+ data = {
1415+ "id" : "existing-node-id" ,
1416+ "name" : {"value" : "JFK1" },
1417+ "description" : {"value" : "JFK Airport" },
1418+ "type" : {"value" : "SITE" },
1419+ }
1420+
1421+ if client_type == "standard" :
1422+ node = InfrahubNode (client = clients .standard , schema = location_schema , data = data )
1423+ else :
1424+ node = InfrahubNodeSync (client = clients .sync , schema = location_schema , data = data )
1425+
1426+ # For existing nodes, optional uninitialized relationships should include None
1427+ assert node ._generate_input_data ()["data" ] == {
1428+ "data" : {
1429+ "id" : "existing-node-id" ,
1430+ "name" : {"value" : "JFK1" },
1431+ "description" : {"value" : "JFK Airport" },
1432+ "type" : {"value" : "SITE" },
13971433 "primary_tag" : None ,
13981434 }
13991435 }
@@ -1642,7 +1678,7 @@ async def test_create_input_data_with_IPHost_attribute(client, ipaddress_schema,
16421678 ip_address = InfrahubNodeSync (client = client , schema = ipaddress_schema , data = data )
16431679
16441680 assert ip_address ._generate_input_data ()["data" ] == {
1645- "data" : {"address" : {"value" : "1.1.1.1/24" , "is_protected" : True }, "interface" : None }
1681+ "data" : {"address" : {"value" : "1.1.1.1/24" , "is_protected" : True }}
16461682 }
16471683
16481684
@@ -1656,7 +1692,7 @@ async def test_create_input_data_with_IPNetwork_attribute(client, ipnetwork_sche
16561692 ip_network = InfrahubNodeSync (client = client , schema = ipnetwork_schema , data = data )
16571693
16581694 assert ip_network ._generate_input_data ()["data" ] == {
1659- "data" : {"network" : {"value" : "1.1.1.0/24" , "is_protected" : True }, "site" : None }
1695+ "data" : {"network" : {"value" : "1.1.1.0/24" , "is_protected" : True }}
16601696 }
16611697
16621698
0 commit comments