Skip to content

Commit 31aeaa0

Browse files
committed
build relationships only if include contains rel name
1 parent f344e76 commit 31aeaa0

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

infrahub_sdk/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ async def _process_nodes_and_relationships(
568568
node = await InfrahubNode.from_graphql(client=self, branch=branch, data=item, timeout=timeout)
569569
nodes.append(node)
570570

571-
if prefetch_relationships or include is not None:
571+
if prefetch_relationships or (include and any(rel in include for rel in node._relationships)):
572572
await node._process_relationships(
573573
node_data=item,
574574
branch=branch,
@@ -1864,7 +1864,7 @@ def _process_nodes_and_relationships(
18641864
node = InfrahubNodeSync.from_graphql(client=self, branch=branch, data=item, timeout=timeout)
18651865
nodes.append(node)
18661866

1867-
if prefetch_relationships or include is not None:
1867+
if prefetch_relationships or (include and any(rel in include for rel in node._relationships)):
18681868
node._process_relationships(node_data=item, branch=branch, related_nodes=related_nodes, timeout=timeout)
18691869

18701870
return ProcessRelationsNodeSync(nodes=nodes, related_nodes=related_nodes)

tests/unit/sdk/conftest.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,20 +2646,3 @@ async def mock_query_tasks_05(httpx_mock: HTTPXMock) -> HTTPXMock:
26462646
is_reusable=True,
26472647
)
26482648
return httpx_mock
2649-
2650-
2651-
async def set_builtin_tag_schema_cache(client) -> None:
2652-
# Set tag schema in cache to avoid needed to request the server.
2653-
builtin_tag_schema = {
2654-
"version": "1.0",
2655-
"nodes": [
2656-
{
2657-
"name": "Tag",
2658-
"namespace": "Builtin",
2659-
"default_filter": "name__value",
2660-
"display_label": "name__value",
2661-
"branch": "aware",
2662-
}
2663-
],
2664-
}
2665-
client.schema.set_cache(builtin_tag_schema)

tests/unit/sdk/test_node.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from infrahub_sdk.node.constants import SAFE_VALUE
1818
from infrahub_sdk.node.related_node import RelatedNode, RelatedNodeSync
1919
from infrahub_sdk.schema import GenericSchema, NodeSchemaAPI
20-
from tests.unit.sdk.conftest import set_builtin_tag_schema_cache
2120

2221
if TYPE_CHECKING:
2322
from infrahub_sdk.client import InfrahubClient, InfrahubClientSync
@@ -54,6 +53,23 @@
5453
]
5554

5655

56+
async def set_builtin_tag_schema_cache(client) -> None:
57+
# Set tag schema in cache to avoid needed to request the server.
58+
builtin_tag_schema = {
59+
"version": "1.0",
60+
"nodes": [
61+
{
62+
"name": "Tag",
63+
"namespace": "Builtin",
64+
"default_filter": "name__value",
65+
"display_label": "name__value",
66+
"branch": "aware",
67+
}
68+
],
69+
}
70+
client.schema.set_cache(builtin_tag_schema)
71+
72+
5773
async def test_method_sanity() -> None:
5874
"""Validate that there is at least one public method and that both clients look the same."""
5975
assert async_node_methods

0 commit comments

Comments
 (0)