Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-29-2023 08:00 PM - edited 01-29-2023 11:54 PM
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:
Please, what could be the problem?
#neo4jdatabase #neo4j #transactions
01-30-2023 12:40 AM - edited 01-30-2023 12:48 AM
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?
01-30-2023 12:46 AM - edited 01-30-2023 12:47 AM
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.)
01-30-2023 12:53 AM
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:
01-30-2023 02:16 AM - edited 01-30-2023 02:19 AM
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.
01-30-2023 05:08 AM
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'>
01-30-2023 05:40 AM
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.
01-30-2023 05:25 AM - edited 01-30-2023 05:31 AM
@rouven_bauer , for some reason, it worked now without any edit. Thanks
All the sessions of the conference are now available online