Skip to content

Commit 21def0a

Browse files
authored
Merge pull request #483 from opsmill/dga-20250724-create-batch
Create batch directly instead of using create_batch while fetching relationships
2 parents 64a7957 + de6cfbf commit 21def0a

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

changelog/+batch.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create a new batch while fetching relationships instead of using the reusing the same one.

infrahub_sdk/node/relationship.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from collections.abc import Iterable
55
from typing import TYPE_CHECKING, Any
66

7+
from ..batch import InfrahubBatch
78
from ..exceptions import (
89
Error,
910
UninitializedError,
@@ -163,12 +164,9 @@ async def fetch(self) -> None:
163164
for peer in self.peers:
164165
if not peer.id or not peer.typename:
165166
raise Error("Unable to fetch the peer, id and/or typename are not defined")
166-
if peer.typename not in ids_per_kind_map:
167-
ids_per_kind_map[peer.typename] = [peer.id]
168-
else:
169-
ids_per_kind_map[peer.typename].append(peer.id)
167+
ids_per_kind_map[peer.typename].append(peer.id)
170168

171-
batch = await self.client.create_batch()
169+
batch = InfrahubBatch(max_concurrent_execution=self.client.max_concurrent_execution)
172170
for kind, ids in ids_per_kind_map.items():
173171
batch.add(
174172
task=self.client.filters,
@@ -289,11 +287,9 @@ def fetch(self) -> None:
289287
for peer in self.peers:
290288
if not peer.id or not peer.typename:
291289
raise Error("Unable to fetch the peer, id and/or typename are not defined")
292-
if peer.typename not in ids_per_kind_map:
293-
ids_per_kind_map[peer.typename] = [peer.id]
294-
else:
295-
ids_per_kind_map[peer.typename].append(peer.id)
290+
ids_per_kind_map[peer.typename].append(peer.id)
296291

292+
# Unlike Async, no need to create a new batch from scratch because we are not using a semaphore
297293
batch = self.client.create_batch()
298294
for kind, ids in ids_per_kind_map.items():
299295
batch.add(

0 commit comments

Comments
 (0)