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.

Read_transaction giving no results; query works fine in browser

dab45
Node Link

Neo4j Desktop version: 1.4.7
Database version: 4.3.1
Driver version: 4.3.4

Hi all,

I'm trying to get...well, any results from my database so far and nothing is coming back. My write_transaction of a works but read_transaction with even a basic query gives nothing, but the same query works fine in the Neo4j browser.

def find_nodes(tx):
    result = tx.run("MATCH (n) RETURN n LIMIT 25")
    return result

with driver.session(database="cophrdf") as session:
    nodes = session.read_transaction(find_nodes)
    for row in nodes:
        print(row)

I get no output from this.

Thanks in advance for any help!

Daniel

1 ACCEPTED SOLUTION

def test_query(tx):
    query = "MATCH (p) RETURN p LIMIT 25"
    result = tx.run(query)
    return [row["p"] for row in result]


with driver.session() as session:
    query_result = session.read_transaction(test_query)

    for node in query_result:
        print(f"Node {list(node.labels)} {dict(node)}")

Works for me. 4.3.4 driver with a 4.3.2 neo4j server. Make sure there are actually nodes in your database.

View solution in original post

5 REPLIES 5

andreperez
Graph Buddy

Try using result.data()
Read about result objects here:

https://neo4j.com/docs/api/python-driver/current/api.html#neo4j.Result

Hi Andre,

Thanks very much for the quick response!

I've also played around with result.data() and unfortunately I get an empty dictionary. Here is the test I did:

def test_query(tx):
    data = {}
    query = ("MATCH (p) RETURN p LIMIT 25")
    result = tx.run(query)
    for key, value in result.data():
        data[key] = value
    return data
    
    
with driver.session() as session:
    query_result = session.read_transaction(test_query)
    
    for key, value in query_result.items():
        print(f"{key}: {value}")

result.keys() gives me 'p' and result.values() is empty.

def test_query(tx):
    query = "MATCH (p) RETURN p LIMIT 25"
    result = tx.run(query)
    return [row["p"] for row in result]


with driver.session() as session:
    query_result = session.read_transaction(test_query)

    for node in query_result:
        print(f"Node {list(node.labels)} {dict(node)}")

Works for me. 4.3.4 driver with a 4.3.2 neo4j server. Make sure there are actually nodes in your database.

dab45
Node Link

Hi again all,

I don't know what changed with the update but after updating my Desktop and Browser versions it suddenly works with both my data test and your code rouven.bauer. My original code still doesn't but I'm going to assume that's me still trying to figure out what's going on here.

Thanks for the replies guys!

Your original code doesn't work because the result goes out of scope when the function (and with it the transaction) ends.

Happy to hear you've got it working.