@@ -229,8 +229,6 @@ async def create_node(
229229                continue 
230230
231231            if  key  in  schema .relationship_names :
232-                 rel_schema  =  schema .get_relationship (name = key )
233- 
234232                rel_info  =  await  get_relationship_info (
235233                    client = client , schema = schema , key = key , value = value , branch = branch 
236234                )
@@ -291,17 +289,13 @@ async def create_node(
291289        client .log .info (f"Node: { display_label }  )
292290
293291        for  rel  in  remaining_rels :
294-             # identify what is the name of the relationship on the other side 
295-             rel_info  =  rels_info [rel ]
296- 
297-             if  rel_schema .identifier  is  None :
298-                 raise  ValueError ("identifier must be defined" )
299- 
300292            context  =  {}
293+ 
294+             # If there is a peer relationship, we add the node id to the context 
295+             rel_info  =  rels_info [rel ]
301296            if  rel_info .peer_rel :
302297                context [rel_info .peer_rel .name ] =  node .id 
303298
304-             # TODO need to account for the different format here 
305299            await  cls .create_related_nodes (
306300                client = client ,
307301                rel_info = rel_info ,
@@ -318,16 +312,18 @@ async def create_related_nodes(
318312        cls ,
319313        client : InfrahubClient ,
320314        rel_info : RelationshipInfo ,
321-         data : dict ,
315+         data : dict   |   list [ dict ] ,
322316        context : dict  |  None  =  None ,
323317        branch : str  |  None  =  None ,
324318        default_schema_kind : str  |  None  =  None ,
325319    ) ->  list [InfrahubNode ]:
326-         peer_schema  =  await  client .schema .get (kind = rel_info .peer_kind , branch = branch )
327- 
328320        nodes : list [InfrahubNode ] =  []
321+         context  =  context  or  {}
322+ 
323+         if  isinstance (data , dict ) and  rel_info .format  ==  RelationshipDataFormat .ONE_OBJ :
324+             peer_kind  =  data .get ("kind" ) or  rel_info .peer_kind 
325+             peer_schema  =  await  client .schema .get (kind = peer_kind , branch = branch )
329326
330-         if  rel_info .format  ==  RelationshipDataFormat .ONE_OBJ :
331327            node  =  await  cls .create_node (
332328                client = client ,
333329                schema = peer_schema ,
@@ -338,8 +334,10 @@ async def create_related_nodes(
338334            )
339335            return  [node ]
340336
341-         if  rel_info .format  ==  RelationshipDataFormat .MANY_OBJ_DICT_LIST :
342-             context  =  context  or  {}
337+         if  isinstance (data , dict ) and  rel_info .format  ==  RelationshipDataFormat .MANY_OBJ_DICT_LIST :
338+             peer_kind  =  data .get ("kind" ) or  rel_info .peer_kind 
339+             peer_schema  =  await  client .schema .get (kind = peer_kind , branch = branch )
340+ 
343341            for  idx , peer_data  in  enumerate (data ["data" ]):
344342                context ["list_index" ] =  idx 
345343                if  isinstance (peer_data , dict ):
@@ -354,8 +352,13 @@ async def create_related_nodes(
354352                    nodes .append (node )
355353            return  nodes 
356354
357-         if  rel_info .format  ==  RelationshipDataFormat .MANY_OBJ_LIST_DICT :
358-             for  item  in  data :
355+         if  isinstance (data , list ) and  rel_info .format  ==  RelationshipDataFormat .MANY_OBJ_LIST_DICT :
356+             for  idx , item  in  enumerate (data ):
357+                 context ["list_index" ] =  idx 
358+ 
359+                 peer_kind  =  item .get ("kind" ) or  rel_info .peer_kind 
360+                 peer_schema  =  await  client .schema .get (kind = peer_kind , branch = branch )
361+ 
359362                node  =  await  cls .create_node (
360363                    client = client ,
361364                    schema = peer_schema ,
@@ -365,6 +368,7 @@ async def create_related_nodes(
365368                    default_schema_kind = default_schema_kind ,
366369                )
367370                nodes .append (node )
371+ 
368372            return  nodes 
369373
370374        raise  ValueError (
0 commit comments