Skip to content

Commit b150e81

Browse files
committed
add some check to make MYPY happy
1 parent 90833c6 commit b150e81

File tree

5 files changed

+96
-12
lines changed

5 files changed

+96
-12
lines changed

infrahub_sdk/ctl/repository.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ async def add(
102102
password=password,
103103
)
104104
await credential.save(allow_upsert=True)
105+
if not credential.id:
106+
raise ValueError("credential.id must be set before building the request")
105107
input_data["data"]["credential"] = {"id": credential.id}
106108

107109
query = Mutation(

infrahub_sdk/node.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,16 +1247,23 @@ async def save(
12471247

12481248
if not isinstance(self._schema, GenericSchemaAPI):
12491249
if "CoreGroup" in self._schema.inherit_from:
1250+
if self.id is None:
1251+
raise UninitializedError("Cannot add related groups before the node has an ID")
12501252
await self._client.group_context.add_related_groups(
12511253
ids=[self.id], update_group_context=update_group_context
12521254
)
12531255
else:
1256+
if self.id is None:
1257+
raise UninitializedError("Cannot add related nodes before the node has an ID")
12541258
await self._client.group_context.add_related_nodes(
12551259
ids=[self.id], update_group_context=update_group_context
12561260
)
12571261
else:
1258-
await self._client.group_context.add_related_nodes(ids=[self.id], update_group_context=update_group_context)
1259-
1262+
if self.id is None:
1263+
raise UninitializedError("Cannot add related nodes before the node has an ID")
1264+
await self._client.group_context.add_related_nodes(
1265+
ids=[self.id], update_group_context=update_group_context
1266+
)
12601267
self._client.store.set(node=self)
12611268

12621269
async def generate_query_data(
@@ -1441,7 +1448,7 @@ async def _process_mutation_result(
14411448
self, mutation_name: str, response: dict[str, Any], timeout: int | None = None
14421449
) -> None:
14431450
object_response: dict[str, Any] = response[mutation_name]["object"]
1444-
self.id = object_response["id"]
1451+
self.id = str(object_response["id"])
14451452
self._existing = True
14461453

14471454
for attr_name in self._attributes:
@@ -1775,10 +1782,19 @@ def save(
17751782

17761783
if not isinstance(self._schema, GenericSchemaAPI):
17771784
if "CoreGroup" in self._schema.inherit_from:
1778-
self._client.group_context.add_related_groups(ids=[self.id], update_group_context=update_group_context)
1785+
if self.id is None:
1786+
raise UninitializedError("Cannot add related nodes before the node has an ID")
1787+
self._client.group_context.add_related_nodes(
1788+
ids=[self.id], update_group_context=update_group_context
1789+
)
1790+
17791791
else:
1792+
if self.id is None:
1793+
raise UninitializedError("Cannot add related nodes before the node has an ID")
17801794
self._client.group_context.add_related_nodes(ids=[self.id], update_group_context=update_group_context)
17811795
else:
1796+
if self.id is None:
1797+
raise UninitializedError("Cannot add related nodes before the node has an ID")
17821798
self._client.group_context.add_related_nodes(ids=[self.id], update_group_context=update_group_context)
17831799

17841800
self._client.store.set(node=self)
@@ -1964,7 +1980,7 @@ def _process_mutation_result(
19641980
self, mutation_name: str, response: dict[str, Any], timeout: int | None = None
19651981
) -> None:
19661982
object_response: dict[str, Any] = response[mutation_name]["object"]
1967-
self.id = object_response["id"]
1983+
self.id = str(object_response["id"])
19681984
self._existing = True
19691985

19701986
for attr_name in self._attributes:

infrahub_sdk/transfer/importer/json.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ async def import_data(self, import_directory: Path, branch: str) -> None:
6565
for graphql_data, kind in zip(table.column("graphql_json"), table.column("kind")):
6666
node = await InfrahubNode.from_graphql(self.client, branch, ujson.loads(str(graphql_data)))
6767
import_nodes_by_kind[str(kind)].append(node)
68-
self.all_nodes[node.id] = node
68+
if node.id:
69+
self.all_nodes[node.id] = node
6970

7071
schema_batch = await self.client.create_batch()
7172
for kind in import_nodes_by_kind:
@@ -112,11 +113,11 @@ async def remove_and_store_optional_relationships(self) -> None:
112113
for relationship_name in self.optional_relationships_schemas_by_node_kind[node_kind].keys():
113114
relationship_value = getattr(node, relationship_name)
114115
if isinstance(relationship_value, RelationshipManager):
115-
if relationship_value.peer_ids:
116+
if relationship_value.peer_ids and node.id:
116117
self.optional_relationships_by_node[node.id][relationship_name] = relationship_value
117118
setattr(node, relationship_name, None)
118119
elif isinstance(relationship_value, RelatedNode):
119-
if relationship_value.id:
120+
if relationship_value.id and node.id:
120121
self.optional_relationships_by_node[node.id][relationship_name] = relationship_value
121122
setattr(node, relationship_name, None)
122123

poetry.lock

Lines changed: 67 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ ujson = "^5"
3232
Jinja2 = { version = "^3", optional = true }
3333
numpy = [
3434
{ version = "^1.24.2", optional = true, python = ">=3.9,<3.12" },
35-
{ version = "^1.26.2", optional = true, python = ">=3.12" },
35+
{ version = "^1.26.2", optional = true, python = "==3.12" },
36+
{ version = "^2.2.6", optional = true, python = ">=3.13" },
3637
]
3738
pyarrow = { version = ">=14", optional = true }
3839
rich = { version = "^13", optional = true }

0 commit comments

Comments
 (0)