cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

The Python examples in https://neo4j.com/docs/api/python-driver/current/ are all broken

The first example for creating nodes fails: I can make it work by removing the 'where' and 'return' clause and add the name directly in the first node but is this example even supposed to work?

from neo4j import GraphDatabase

uri = "neo4j://localhost:7687"
driver = GraphDatabase.driver(uri, auth=("neo4j", "password"))

def create_friend_of(tx, name, friend):
    tx.run("CREATE (a:Person)-[:KNOWS]->(f:Person {name: $friend}) "
           "WHERE a.name = $name "
           "RETURN f.name AS friend", name=name, friend=friend)

with driver.session() as session:
    session.write_transaction(create_friend_of, "Alice", "Bob")

with driver.session() as session:
    session.write_transaction(create_friend_of, "Alice", "Carl")

driver.close()

and here is the error:

    response.on_failure(summary_metadata or {})
  File "/home/test/anaconda3/envs/jsonld/lib/python3.7/site-packages/neo4j/io/_bolt4x1.py", line 541, in on_failure
    raise Neo4jError.hydrate(**metadata)
neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input 'H': expected 'i/I' (line 1, column 57 (offset: 56))
"CREATE (a:Person)-[:KNOWS]->(f:Person {name: $friend}) WHERE a.name = $name RETURN f.name AS friend"

again: if I change the code to this (see below) I get it to work but wouldn't it be nice if the example worked?

def create_friend_of(tx, name, friend):
    tx.run("CREATE (a:Person {name: $name})-[:KNOWS]->(f:Person {name: $friend})", name=name, friend=friend)

The second example also doesn't work but if you take off the ':' after name=name the exmple will
work

here is the wrong code with the colon that shouldn't be there


def get_friends_of(tx, name):
    friends = []
    result = tx.run("MATCH (a:Person)-[:KNOWS]->(f) "
                    "WHERE a.name = $name "
                    "RETURN f.name AS friend", name=name):
    for record in result:
        friends.append(record["friend"])
    return friends
0 REPLIES 0