1
votes

My simple code is retrieving attributes from nodes in neo4j.

results = graph.cypher.execute("MATCH (m)-[:AB]->(a) " "RETURN m.searchField as origin, a.searchField as destination " "LIMIT {limit}", {"limit": 100}) nodes = [] rels = [] i = 0 for r in results: print (r)
ent1 = {"title": r.origin, "label": "entity"}

but the server returns "NameError("global name 'searchField' is not defined",)" Certainly I missed something, but I'm puzzled that the searchField inside the Cypher query is the object of the error. This is still with py2neo 2.0.8. Thanks for any pointer, hj

Later editing: Thanks for taking the time to look at this question. Two elements further puzzle me in this error: 1. The query in cypher is fine, and returns the result I expect in neo4j-shell without problem 2. This code seems to work fine when I run bottle as standalone (run(port=8080) in main), but fails when I run it as wsgi under an apache server. I am wondering if it is a problem of running user, or of context in some part of the code.

2

2 Answers

0
votes

Do you have a property called searchField on the node(s)? If not, the query will fail.

BTW, it is easier to use a string for the query like so:

query = '''
MATCH (m)-[:AB]->(a)
RETURN m.searchField as origin, a.searchField as destination 
LIMIT {limit}
'''
result = graph.cypher.execute(query, limit='foo')
0
votes

Got it to work! It was unrelated to code, but I did not know that any refresh of a new python code served through wsgi requires an apache reload at least.

sudo service apache2 reload

With that I obtain the same (and correct) behavior as with the direct server. The error was the result of an old version of the code... newbie mistake!

Thanks and sorry for the hassle, hj