Skip to content

Commit

Permalink
Fix HFID when using generic relationship attributes (#4238)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazoyer authored Sep 2, 2024
1 parent a10e3a4 commit 56abac7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
1 change: 1 addition & 0 deletions python_sdk/changelog/3900.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix fetching relationship attributes when relationship inherits from a generic
24 changes: 5 additions & 19 deletions python_sdk/infrahub_sdk/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,11 +1067,7 @@ def __init__(

@classmethod
async def from_graphql(
cls,
client: InfrahubClient,
branch: str,
data: dict,
schema: Optional[MainSchemaTypes] = None,
cls, client: InfrahubClient, branch: str, data: dict, schema: Optional[MainSchemaTypes] = None
) -> Self:
if not schema:
node_kind = data.get("__typename", None) or data.get("node", {}).get("__typename", None)
Expand Down Expand Up @@ -1279,7 +1275,7 @@ async def generate_query_data_node(
if rel_schema and prefetch_relationships:
peer_schema = await self._client.schema.get(kind=rel_schema.peer, branch=self._branch)
peer_node = InfrahubNode(client=self._client, schema=peer_schema, branch=self._branch)
peer_data = await peer_node.generate_query_data_node(include=include, exclude=exclude, inherited=False)
peer_data = await peer_node.generate_query_data_node(include=include, exclude=exclude)

if rel_schema and rel_schema.cardinality == "one":
rel_data = RelatedNode._generate_query_data(peer_data=peer_data)
Expand Down Expand Up @@ -1548,11 +1544,7 @@ def __init__(

@classmethod
def from_graphql(
cls,
client: InfrahubClientSync,
branch: str,
data: dict,
schema: Optional[MainSchemaTypes] = None,
cls, client: InfrahubClientSync, branch: str, data: dict, schema: Optional[MainSchemaTypes] = None
) -> Self:
if not schema:
node_kind = data.get("__typename", None) or data.get("node", {}).get("__typename", None)
Expand Down Expand Up @@ -1752,7 +1744,7 @@ def generate_query_data_node(
if rel_schema and prefetch_relationships:
peer_schema = self._client.schema.get(kind=rel_schema.peer, branch=self._branch)
peer_node = InfrahubNodeSync(client=self._client, schema=peer_schema, branch=self._branch)
peer_data = peer_node.generate_query_data_node(include=include, exclude=exclude, inherited=False)
peer_data = peer_node.generate_query_data_node(include=include, exclude=exclude)

if rel_schema and rel_schema.cardinality == "one":
rel_data = RelatedNodeSync._generate_query_data(peer_data=peer_data)
Expand Down Expand Up @@ -2051,13 +2043,7 @@ def prop(self, value): # type: ignore
setattr(
self,
internal_name,
node_class(
name=external_name,
branch=node._branch,
client=node._client,
schema=schema,
data=value,
),
node_class(name=external_name, branch=node._branch, client=node._client, schema=schema, data=value),
)

return prop

0 comments on commit 56abac7

Please sign in to comment.