Skip to content

Refresh python packages #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: stable
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions infrahub_sdk/ctl/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
password=password,
)
await credential.save(allow_upsert=True)
if not credential.id:
raise ValueError("credential.id must be set before building the request")

Check warning on line 106 in infrahub_sdk/ctl/repository.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/ctl/repository.py#L106

Added line #L106 was not covered by tests
input_data["data"]["credential"] = {"id": credential.id}

query = Mutation(
Expand Down
20 changes: 16 additions & 4 deletions infrahub_sdk/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,16 +1247,21 @@

if not isinstance(self._schema, GenericSchemaAPI):
if "CoreGroup" in self._schema.inherit_from:
if self.id is None:
raise UninitializedError("Cannot add related groups before the node has an ID")

Check warning on line 1251 in infrahub_sdk/node.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/node.py#L1251

Added line #L1251 was not covered by tests
await self._client.group_context.add_related_groups(
ids=[self.id], update_group_context=update_group_context
)
else:
if self.id is None:
raise UninitializedError("Cannot add related nodes before the node has an ID")

Check warning on line 1257 in infrahub_sdk/node.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/node.py#L1257

Added line #L1257 was not covered by tests
await self._client.group_context.add_related_nodes(
ids=[self.id], update_group_context=update_group_context
)
else:
if self.id is None:
raise UninitializedError("Cannot add related nodes before the node has an ID")

Check warning on line 1263 in infrahub_sdk/node.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/node.py#L1263

Added line #L1263 was not covered by tests
await self._client.group_context.add_related_nodes(ids=[self.id], update_group_context=update_group_context)

self._client.store.set(node=self)

async def generate_query_data(
Expand Down Expand Up @@ -1441,7 +1446,7 @@
self, mutation_name: str, response: dict[str, Any], timeout: int | None = None
) -> None:
object_response: dict[str, Any] = response[mutation_name]["object"]
self.id = object_response["id"]
self.id = str(object_response["id"])
self._existing = True

for attr_name in self._attributes:
Expand Down Expand Up @@ -1775,10 +1780,17 @@

if not isinstance(self._schema, GenericSchemaAPI):
if "CoreGroup" in self._schema.inherit_from:
self._client.group_context.add_related_groups(ids=[self.id], update_group_context=update_group_context)
if self.id is None:
raise UninitializedError("Cannot add related nodes before the node has an ID")
self._client.group_context.add_related_nodes(ids=[self.id], update_group_context=update_group_context)

Check warning on line 1785 in infrahub_sdk/node.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/node.py#L1784-L1785

Added lines #L1784 - L1785 were not covered by tests

else:
if self.id is None:
raise UninitializedError("Cannot add related nodes before the node has an ID")

Check warning on line 1789 in infrahub_sdk/node.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/node.py#L1789

Added line #L1789 was not covered by tests
self._client.group_context.add_related_nodes(ids=[self.id], update_group_context=update_group_context)
else:
if self.id is None:
raise UninitializedError("Cannot add related nodes before the node has an ID")

Check warning on line 1793 in infrahub_sdk/node.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/node.py#L1793

Added line #L1793 was not covered by tests
self._client.group_context.add_related_nodes(ids=[self.id], update_group_context=update_group_context)

self._client.store.set(node=self)
Expand Down Expand Up @@ -1964,7 +1976,7 @@
self, mutation_name: str, response: dict[str, Any], timeout: int | None = None
) -> None:
object_response: dict[str, Any] = response[mutation_name]["object"]
self.id = object_response["id"]
self.id = str(object_response["id"])
self._existing = True

for attr_name in self._attributes:
Expand Down
7 changes: 4 additions & 3 deletions infrahub_sdk/transfer/importer/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
for graphql_data, kind in zip(table.column("graphql_json"), table.column("kind")):
node = await InfrahubNode.from_graphql(self.client, branch, ujson.loads(str(graphql_data)))
import_nodes_by_kind[str(kind)].append(node)
self.all_nodes[node.id] = node
if node.id:
self.all_nodes[node.id] = node

Check warning on line 69 in infrahub_sdk/transfer/importer/json.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/transfer/importer/json.py#L69

Added line #L69 was not covered by tests

schema_batch = await self.client.create_batch()
for kind in import_nodes_by_kind:
Expand Down Expand Up @@ -112,11 +113,11 @@
for relationship_name in self.optional_relationships_schemas_by_node_kind[node_kind].keys():
relationship_value = getattr(node, relationship_name)
if isinstance(relationship_value, RelationshipManager):
if relationship_value.peer_ids:
if relationship_value.peer_ids and node.id:
self.optional_relationships_by_node[node.id][relationship_name] = relationship_value
setattr(node, relationship_name, None)
elif isinstance(relationship_value, RelatedNode):
if relationship_value.id:
if relationship_value.id and node.id:
self.optional_relationships_by_node[node.id][relationship_name] = relationship_value
setattr(node, relationship_name, None)

Expand Down
Loading