Skip to content

Commit e05ef4f

Browse files
committed
Fix issue with related nodes
1 parent ef91f25 commit e05ef4f

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

docs/docs/python-sdk/topics/object_file.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ spec:
6464

6565
> Multiple documents in a single YAML file are also supported, each document will be loaded separately. Documents are separated by `---`
6666

67-
### Relationship of cardinality One
67+
### Relationship of cardinality one
6868

6969
A relationship of cardinality one can either reference an existing node via its HFID or create a new node if it doesn't exist.
7070
In the example below, both `site` and `primary_ip` are relationships of cardinality one.
@@ -83,7 +83,7 @@ spec:
8383
address: "192.168.1.1"
8484
```
8585

86-
### Relationship of cardinality Many
86+
### Relationship of cardinality many
8787

8888
A relationship of cardinality many can reference existing nodes via their HFID or define nested objects.
8989

@@ -111,7 +111,7 @@ spec:
111111
- [Breeder] # Existing Node referenced by its HFID in list format
112112
```
113113

114-
#### Nested Objects
114+
#### Nested objects
115115

116116
When defining nested objects, the node will be automatically created if it doesn't exist and if the relationship between the parent object and the nested object exists, it will be automatically inserted.
117117
For example, in the example below, the `owner` of a `TestingDog` doesn't need to be specified because it will be automatically inserted.
@@ -175,19 +175,19 @@ spec:
175175
breed: Persian
176176
```
177177

178-
### Support for Metadata
178+
### Support for metadata
179179

180180
Metadata support is planned for future releases. Currently, the Object file does not support metadata on attributes or relationships.
181181

182182
## Troubleshooting
183183

184-
### Common Issues
184+
### Common issues
185185

186186
1. **Objects not being created**: Ensure that the YAML syntax is correct and that the file follows the required format.
187187
2. **Dependency errors**: When objects depend on each other, load them in the correct order (dependencies first).
188188
3. **Validation errors**: Use the `infrahub object validate` command to check for syntax errors before loading.
189189

190-
### Best Practices
190+
### Best practices
191191

192192
1. Use Human Friendly IDs (HFIDs) for all objects to ensure consistent referencing.
193193
2. Keep object files organized by model type or purpose.

infrahub_sdk/spec/object.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ async def create_node(
433433

434434
await cls.create_related_nodes(
435435
client=client,
436-
node=node,
436+
parent_node=node,
437437
rel_info=rel_info,
438438
position=position,
439439
data=data[rel],
@@ -451,7 +451,7 @@ async def create_related_nodes(
451451
rel_info: RelationshipInfo,
452452
position: list[int | str],
453453
data: dict | list[dict],
454-
node: InfrahubNode | None = None,
454+
parent_node: InfrahubNode | None = None,
455455
context: dict | None = None,
456456
branch: str | None = None,
457457
default_schema_kind: str | None = None,
@@ -463,11 +463,11 @@ async def create_related_nodes(
463463
peer_kind = data.get("kind") or rel_info.peer_kind
464464
peer_schema = await client.schema.get(kind=peer_kind, branch=branch)
465465

466-
if node:
466+
if parent_node:
467467
rel_info.find_matching_relationship(peer_schema=peer_schema)
468-
context.update(rel_info.get_context(value=node.id))
468+
context.update(rel_info.get_context(value=parent_node.id))
469469

470-
node = await cls.create_node(
470+
new_node = await cls.create_node(
471471
client=client,
472472
schema=peer_schema,
473473
position=position,
@@ -476,15 +476,15 @@ async def create_related_nodes(
476476
branch=branch,
477477
default_schema_kind=default_schema_kind,
478478
)
479-
return [node]
479+
return [new_node]
480480

481481
if isinstance(data, dict) and rel_info.format == RelationshipDataFormat.MANY_OBJ_DICT_LIST:
482482
peer_kind = data.get("kind") or rel_info.peer_kind
483483
peer_schema = await client.schema.get(kind=peer_kind, branch=branch)
484484

485-
if node:
485+
if parent_node:
486486
rel_info.find_matching_relationship(peer_schema=peer_schema)
487-
context.update(rel_info.get_context(value=node.id))
487+
context.update(rel_info.get_context(value=parent_node.id))
488488

489489
for idx, peer_data in enumerate(data["data"]):
490490
context["list_index"] = idx
@@ -508,9 +508,9 @@ async def create_related_nodes(
508508
peer_kind = item.get("kind") or rel_info.peer_kind
509509
peer_schema = await client.schema.get(kind=peer_kind, branch=branch)
510510

511-
if node:
511+
if parent_node:
512512
rel_info.find_matching_relationship(peer_schema=peer_schema)
513-
context.update(rel_info.get_context(value=node.id))
513+
context.update(rel_info.get_context(value=parent_node.id))
514514

515515
node = await cls.create_node(
516516
client=client,

0 commit comments

Comments
 (0)