ArangoDB-Community / pyArango

Python Driver for ArangoDB with built-in validation
https://pyarango.readthedocs.io/en/latest/
Apache License 2.0
237 stars 90 forks source link

Problem creating graph from existing edge collections #223

Open pedrocassalpacheco opened 2 years ago

pedrocassalpacheco commented 2 years ago

Code: networks = ["co", "mg", "ne", "no", "rj", "sul"] edges = []

for network in networks: edges_collection_name = network + "_edges" node_collection_name = network + "_routers" print edges.append(EdgeDefinition(edges_collection_name, fromCollections=[node_collection_name], toCollections=[node_collection_name]))

class RSNac1(Graph) : _edgeDefinitions = edges _orphanedCollections = []

theGraph = db.createGraph("RSNac1", createCollections=True)

Output:

ValueError Traceback (most recent call last)

in 16 _orphanedCollections = [] 17 ---> 18 theGraph = db.createGraph("RSNac1", createCollections=True) /opt/anaconda3/lib/python3.8/site-packages/pyArango/database.py in createGraph(self, name, createCollections, isSmart, numberOfShards, smartGraphAttribute, replicationFactor, writeConcern) 159 for e in graphClass._edgeDefinitions: 160 if not COL.isEdgeCollection(e.edgesCollection): --> 161 raise ValueError("'%s' is not a defined Edge Collection" % e.edgesCollection) 162 _checkCollectionList(e.fromCollections) 163 _checkCollectionList(e.toCollections) ValueError: 'co_edges' is not a defined Edge Collection Data: db.collections["co_edges"] ArangoDB collection name: co_edges, id: 6814744, type: edge, status: loaded What have I tried: Used example to create collections and graphs. Collections and graphs use class templates. Works Used the code above where the collection (edge and node) are already on the database. Not that error is a false negavite. The collection is an edge collection
tariqdaouda commented 2 years ago

Have you checked in the GUI that all edge definitions are the same as is in the python definition? It seems that you are referencing an edge collection named "co_edges" that was not created before hand (i.e. not present in the database).

Also you cannot change definitions once the graph is created in ArangoDB. If you add and edge collection to the code after the creation of the graph, that edge collection will not be added to the graph definition in ArangoDB.

pedrocassalpacheco commented 2 years ago

Yes, I did. Unless the collections are created by the code, the COL.isCollection (or something like that fails) albeit the collection exists. Just so I could finish what I was working on, I simply removed the checks and it worked.

for e in graphClass._edgeDefinitions:

if not COL.isEdgeCollection(e.edgesCollection):

        #    raise ValueError("'%s' is not a defined Edge Collection" % e.edgesCollection)
        #_checkCollectionList(e.fromCollections)
        #_checkCollectionList(e.toCollections)

I know, I hacked it :)