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.

TypeError: Unit of work is not callable

Reuben
Graph Buddy

Please I have challenge:

Although the function as illustrated below, is defined correctly as a callable function taking 2 arguments, tx and path, and it is being passed correctly as the first argument to session.execute_write(fn, path). I get the error:

TypeError: Unit of work is not callable

I thought the problem could be arising from the version of the neo4j python driver I am using or that there is an issue with the driver's configuration or the version of the neo4j python driver or Neo4j server. But there is no issue as well. I also update my neo4j Desktop to 4.4.7 but I Still can't figure out why the argument passed to execute_write is not a callable function. 

Here is the section:

 

 



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

flow_file = 'file:///lca/user_data.csv'

def detach_and_delete(tx):
    tx.run(
        "MATCH (n) DETACH DELETE n "
    )
def flow(tx,path):
    tx.run (

    "LOAD CSV WITH HEADERS FROM $path AS row "  
    "MERGE (f:flows {name: row.flow_name}) "
    "MERGE (m:mate {name: row.mate}) "
    "MERGE (f)-[:mate_is]->(m) "
    , path=path
    )

with driver.session() as session:
    
    session.execute_write(detach_and_delete)
    session.execute_write(flow,path=flow_file)

 

Error message:

 

Screenshot 2023-01-30 at 15.43.25.png

 

 

 

 

Please, what could be the problem?

@glilienfield @elena_kohlwey 

#neo4jdatabase #neo4j #transactions 

7 REPLIES 7

rouven_bauer
Neo4j
Neo4j

Hi, this looks odd. Can you please share the full stacktrace?

Also, which exact version of the driver and what Python version are you running?

rouven_bauer
Neo4j
Neo4j

I'm asking because what I can't see is if the error really originated from session.execute_write(flow,path=flow_file) or some other place. Then (should it really be that line) please also double-check that the variable flow really contains what you think it does and that it didn't get overwritten or something.

Because when I run that exact code snipped you posted it works for me (except for the server giving me an error neo4j.exceptions.ClientError: {code: Neo.ClientError.Statement.ExternalResourceFailed} {message: Couldn't load the external resource at: file:/var/lib/neo4j/import/lca/user_data.csv}, but that's expected because I didn't put any CSV file anywhere.)

Hi Rouven; thanks for the response. So what I shared is a snippet, of one function, where the error is indicated. Kindly see if this gives you any idea as to what I should look out for:

Screenshot 2023-01-30 at 16.49.33.png

 

Thanks. Yeah, you've correctly identified that it's coming from that line. So let's try to find out what's going wrong. What output do you get if you put print(flow, type(flow)) right before line 10 (session.execute_write(flow,path=flow_file))?

Also, please share which exact versions of the driver and Python interpreter you're running.

if I print just: "print(flow, type(flow))", I get this output. 

<pandas.io.excel._base.ExcelFile object at 0x7fe70f228340> <class 'pandas.io.excel._base.ExcelFile'>

 

Yep. That's what I though. flow what not the function you thought it was. Your screenshots suggest you're wokring in a jupyter notebook or similar. It's quite easy to trip over overwritten global variables. Especially if you don't exeute the cells top to bottom.

@rouven_bauer , for some reason, it worked now without any edit. Thanks