Skip to content

Commit 753b632

Browse files
committed
fix: GraphNotEmpty logic
1 parent 8ab094b commit 753b632

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

nx_arangodb/classes/graph.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -446,18 +446,18 @@ def edge_type_func(u: str, v: str) -> str:
446446
def _load_nx_graph(
447447
self, nx_graph: nx.Graph, write_batch_size: int, write_async: bool
448448
) -> None:
449-
v_count = sum(
450-
self.db.collection(v).count() for v in self.adb_graph.vertex_collections()
451-
)
449+
collections = list(self.adb_graph.vertex_collections())
450+
collections += [e["edge_collection"] for e in self.adb_graph.edge_definitions()]
452451

453-
e_count = sum(
454-
self.db.collection(e["edge_collection"]).count()
455-
for e in self.adb_graph.edge_definitions()
456-
)
452+
for col in collections:
453+
cursor = self.db.aql.execute(
454+
"FOR doc IN @@collection LIMIT 1 RETURN 1",
455+
bind_vars={"@collection": col},
456+
)
457457

458-
if v_count > 0 or e_count > 0:
459-
m = f"Graph '{self.adb_graph.name}' already has data. Use **overwrite_graph=True** to clear it." # noqa: E501
460-
raise GraphNotEmpty(m)
458+
if not cursor.empty():
459+
m = f"Graph '{self.adb_graph.name}' already has data (in '{col}'). Use **overwrite_graph=True** to clear it." # noqa: E501
460+
raise GraphNotEmpty(m)
461461

462462
controller = ADBNX_Controller
463463

0 commit comments

Comments
 (0)