@@ -204,7 +204,7 @@ def __init__(
204204
205205 self .__set_db (db )
206206 if all ([self .__db , name ]):
207- self .__set_graph (name , default_node_type , edge_type_func )
207+ self .__set_graph (name , overwrite_graph , default_node_type , edge_type_func )
208208 self .__set_edge_collections_attributes (edge_collections_attributes )
209209
210210 # NOTE: Need to revisit these...
@@ -228,24 +228,7 @@ def __init__(
228228 self ._loaded_incoming_graph_data = False
229229 if self .graph_exists_in_db :
230230 self ._set_factory_methods ()
231- self .__set_arangodb_backend_config (read_parallelism , read_batch_size )
232-
233- if overwrite_graph :
234- logger .info ("Overwriting graph..." )
235-
236- properties = self .adb_graph .properties ()
237- self .db .delete_graph (name , drop_collections = True )
238- self .db .create_graph (
239- name = name ,
240- edge_definitions = properties ["edge_definitions" ],
241- orphan_collections = properties ["orphan_collections" ],
242- smart = properties .get ("smart" ),
243- disjoint = properties .get ("disjoint" ),
244- smart_field = properties .get ("smart_field" ),
245- shard_count = properties .get ("shard_count" ),
246- replication_factor = properties .get ("replication_factor" ),
247- write_concern = properties .get ("write_concern" ),
248- )
231+ self .__set_arangodb_backend_config (read_parallelism , read_batch_size )
249232
250233 if isinstance (incoming_graph_data , nx .Graph ):
251234 self ._load_nx_graph (incoming_graph_data , write_batch_size , write_async )
@@ -372,13 +355,33 @@ def __set_db(self, db: Any = None) -> None:
372355 def __set_graph (
373356 self ,
374357 name : Any ,
358+ overwrite_graph : bool ,
375359 default_node_type : str | None = None ,
376360 edge_type_func : Callable [[str , str ], str ] | None = None ,
377361 ) -> None :
378362 if not isinstance (name , str ):
379363 raise TypeError ("**name** must be a string" )
380364
381- if self .db .has_graph (name ):
365+ graph_exists = self .db .has_graph (name )
366+
367+ if graph_exists and overwrite_graph :
368+ logger .info (f"Overwriting graph '{ name } '" )
369+
370+ properties = self .adb_graph .properties ()
371+ self .db .delete_graph (name , drop_collections = True )
372+ self .db .create_graph (
373+ name = name ,
374+ edge_definitions = properties ["edge_definitions" ],
375+ orphan_collections = properties ["orphan_collections" ],
376+ smart = properties .get ("smart" ),
377+ disjoint = properties .get ("disjoint" ),
378+ smart_field = properties .get ("smart_field" ),
379+ shard_count = properties .get ("shard_count" ),
380+ replication_factor = properties .get ("replication_factor" ),
381+ write_concern = properties .get ("write_concern" ),
382+ )
383+
384+ if graph_exists :
382385 logger .info (f"Graph '{ name } ' exists." )
383386
384387 if edge_type_func is not None :
0 commit comments