Skip to content

Commit 2209180

Browse files
committed
new: GraphNotEmpty exception
1 parent 3ca0f12 commit 2209180

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

nx_arangodb/classes/graph.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
DatabaseNotSet,
1616
EdgeTypeAmbiguity,
1717
GraphNameNotSet,
18+
GraphNotEmpty,
1819
InvalidDefaultNodeType,
1920
)
2021
from nx_arangodb.logger import logger
@@ -439,6 +440,19 @@ def edge_type_func(u: str, v: str) -> str:
439440
def _load_nx_graph(
440441
self, nx_graph: nx.Graph, write_batch_size: int, write_async: bool
441442
) -> None:
443+
v_count = sum(
444+
self.db.collection(v).count() for v in self.adb_graph.vertex_collections()
445+
)
446+
447+
e_count = sum(
448+
self.db.collection(e["edge_collection"]).count()
449+
for e in self.adb_graph.edge_definitions()
450+
)
451+
452+
if v_count > 0 or e_count > 0:
453+
m = f"Graph '{self.adb_graph.name}' already has data. Use **overwrite_graph=True** to clear it." # noqa: E501
454+
raise GraphNotEmpty(m)
455+
442456
controller = ADBNX_Controller
443457

444458
if all([self.is_smart, self.smart_field]):

nx_arangodb/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class GraphNameNotSet(NetworkXArangoDBException):
1414
pass
1515

1616

17+
class GraphNotEmpty(NetworkXArangoDBException):
18+
pass
19+
20+
1721
class InvalidTraversalDirection(NetworkXArangoDBException):
1822
pass
1923

0 commit comments

Comments
 (0)