Skip to content
Draft
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
31 changes: 31 additions & 0 deletions docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/related_node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
id(self) -> str | None
```

Return the parsed peer id without triggering a store lookup.

Returns None when the response carried only hfid_str (no id, no peer)
— in that case .peer.id would resolve through the store and yield a
non-None id, so .id and .peer.id are NOT interchangeable.

#### `hfid`

```python
Expand Down Expand Up @@ -95,12 +101,24 @@
peer(self) -> InfrahubNode
```

Return the peer node, or raise ValueError if no identifier is available.

#### `get`

```python
get(self) -> InfrahubNode
```

Return the peer node, performing a store lookup if not materialized.

When resolving via hfid_str the returned node has a non-None id even
when this RelatedNode's .id is None — that is the case in which
.peer.id and .id diverge.

**Raises:**
- `ValueError`: when neither a peer, (_id, _typename), nor hfid_str

Check failure on line 119 in docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/related_node.mdx

View workflow job for this annotation

GitHub Actions / markdown-lint

Spaces inside emphasis markers

docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/related_node.mdx:119:43 MD037/no-space-in-emphasis Spaces inside emphasis markers [Context: ", _"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md037.md

Check failure on line 119 in docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/related_node.mdx

View workflow job for this annotation

GitHub Actions / markdown-lint

Lists should be surrounded by blank lines

docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/related_node.mdx:119 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- `ValueError`: when neither a..."] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md032.md
is available.

### `RelatedNodeSync`

Represents a related node in a synchronous context.
Expand All @@ -119,8 +137,21 @@
peer(self) -> InfrahubNodeSync
```

Return the peer node, or raise ValueError if no identifier is available.

#### `get`

```python
get(self) -> InfrahubNodeSync
```

Return the peer node, performing a store lookup if not materialized.

When resolving via hfid_str the returned node has a non-None id even
when this RelatedNode's .id is None — that is the case in which
.peer.id and .id diverge.

**Raises:**
- `ValueError`: when neither a peer, (_id, _typename), nor hfid_str

Check failure on line 155 in docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/related_node.mdx

View workflow job for this annotation

GitHub Actions / markdown-lint

Spaces inside emphasis markers

docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/related_node.mdx:155:43 MD037/no-space-in-emphasis Spaces inside emphasis markers [Context: ", _"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md037.md

Check failure on line 155 in docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/related_node.mdx

View workflow job for this annotation

GitHub Actions / markdown-lint

Lists should be surrounded by blank lines

docs/docs/python-sdk/sdk_ref/infrahub_sdk/node/related_node.mdx:155 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- `ValueError`: when neither a..."] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md032.md
is available.

28 changes: 28 additions & 0 deletions infrahub_sdk/node/related_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ def __init__(self, branch: str, schema: RelationshipSchemaAPI, data: Any | dict,

@property
def id(self) -> str | None:
"""Return the parsed peer id without triggering a store lookup.

Returns None when the response carried only hfid_str (no id, no peer)
— in that case .peer.id would resolve through the store and yield a
non-None id, so .id and .peer.id are NOT interchangeable.
"""
if self._peer:
return self._peer.id
return self._id
Expand Down Expand Up @@ -242,9 +248,20 @@ async def fetch(self, timeout: int | None = None) -> None:

@property
def peer(self) -> InfrahubNode:
"""Return the peer node, or raise ValueError if no identifier is available."""
return self.get()

def get(self) -> InfrahubNode:
"""Return the peer node, performing a store lookup if not materialized.

When resolving via hfid_str the returned node has a non-None id even
when this RelatedNode's .id is None — that is the case in which
.peer.id and .id diverge.

Raises:
ValueError: when neither a peer, (_id, _typename), nor hfid_str
is available.
"""
if self._peer:
return self._peer # type: ignore[return-value]

Expand Down Expand Up @@ -289,9 +306,20 @@ def fetch(self, timeout: int | None = None) -> None:

@property
def peer(self) -> InfrahubNodeSync:
"""Return the peer node, or raise ValueError if no identifier is available."""
return self.get()

def get(self) -> InfrahubNodeSync:
"""Return the peer node, performing a store lookup if not materialized.

When resolving via hfid_str the returned node has a non-None id even
when this RelatedNode's .id is None — that is the case in which
.peer.id and .id diverge.

Raises:
ValueError: when neither a peer, (_id, _typename), nor hfid_str
is available.
"""
if self._peer:
return self._peer # type: ignore[return-value]

Expand Down
Loading