I am using the following code to figure out if an Edge definition is existing already and either get a NameError
or a False
where should be a True
.
The code is the following:
@staticmethod
def doesGraphHasEdgeDefinition(arangograph, edge_collection, from_node_collections, to_node_collections):
if edge_collection in [eg['edge_collection'] for eg in arangograph.edge_definitions()]:
if all(item in [fvc['from_vertex_collections'] for fvc in arangograph.edge_definitions()] for item in from_node_collections):
if all(item in [tvc['to_vertex_collections'] for tvc in arangograph.edge_definitions()] for item in to_node_collections):
return True
else:
logging.debug("To-Node Collections are different")
return False
else:
logging.debug("From-Node Collections are different already")
return False
else:
logging.debug("Edge Collections are different already")
return False
But when debugging with ipdb I constantly get an error in the line:
ipdb> !all(item in [fvc['from_vertex_collections'] for fvc in arangograph.edge_definitions()] for item in from_node_collections)
*** NameError: name 'arangograph' is not defined
Strangely the line before:
ipdb> !edge_collection in [eg['edge_collection'] for eg in arangograph.edge_definitions()]
True
Even though this is for ArangoDB I'm not working with specific ArangoDB objects and the code can just be called with the set values. Here is the debugging output before the line where the error appears:
ipdb> arangograph
<Graph testgraph>
ipdb> edge_collection
'nj_EDGES'
ipdb> from_node_collections
['nj_NODES']
ipdb> to_node_collections
['nj_NODES']
arangograph.edge_definitions()
is just a list containing a dict with strings, so the problem is not related to the ArangoDB-Framework:
ipdb> arangograph.edge_definitions()
[{'edge_collection': 'nj_EDGES', 'from_vertex_collections': ['nj_NODES'], 'to_vertex_collections': ['nj_NODES']}]
It gets weirder. The code runs without the error but the if-statement in question returns False
, despite:
ipdb> !helper =[item in [fvc['from_vertex_collections'] for fvc in arangograph.edge_definitions()] for item in from_node_collections]
*** NameError: name 'arangograph' is not defined
ipdb> !all(helper)
True
I start to assume it's an issue with the ipdb.
So I am trying something else:
ipdb> fvclist=[fvc['from_vertex_collections'] for fvc in arangograph.edge_definitions()]
ipdb> fvclist
[['nj_NODES']]
ipdb> fvclist
[['nj_NODES']]
ipdb> from_node_collections
['nj_NODES']
ipdb> type(fvclist)
<class 'list'>
ipdb> type(from_node_collections)
<class 'list'>
ipdb> !set(from_node_collections).issubset(fvclist)
*** TypeError: unhashable type: 'list'
ipdb> !any(from_node_collections in sublist for sublist in fvclist)
*** NameError: name 'from_node_collections' is not defined
How am I supposed to debug this properly? Am I overseeing something?
I'm doing the debug on IPython 7.24.0 with:
import ipdb
ipdb.set_trace()
On Python 3.8.5 (default, May 27 2021, 13:30:53)
pyArango
but that's not related to the error as it returns what it is supposed to.