Hi
I am having some issues when running the neo4j python library
I am running a query, it works as expected, but when the execution ends, i have this error:
Exception ignored in: <function Driver.del at 0x12cb25670>
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/neo4j/_sync/driver.py", line 485, in del
File "/opt/homebrew/lib/python3.9/site-packages/neo4j/_meta.py", line 226, in unclosed_resource_warn
TypeError: 'NoneType' object is not callable
Exception ignored in: <function Workspace.del at 0x12cb20940>
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/neo4j/_sync/work/workspace.py", line 65, in del
File "/opt/homebrew/lib/python3.9/site-packages/neo4j/_meta.py", line 226, in unclosed_resource_warn
TypeError: 'NoneType' object is not callable
My code is as simple as this:
driver = GraphDatabase.driver(os.environ.get('NEO4J_DB'),
auth=(os.environ.get('NEO4J_USER'), os.environ.get('NEO4J_PWD')))
driver.session()
driver.execute_query('''
MERGE (n:project {project_name: $project})
''', project=project.get('name'))
driver.close()
Any idea why i am having this error and how to get rid of it?
Thanks
You don’t need the driver.session() call since the driver.execute_query call creates its own transaction. You are not using the session created anyway. Delete that call.
The logs mention an ‘unclosed resource warning’. Maybe it is due the hanging session.
Still the same… Do I need the driver close either?
Maybe you need to consume the results, although you aren't returning any. You could try this:
driver = GraphDatabase.driver(os.environ.get('NEO4J_DB'),
auth=(os.environ.get('NEO4J_USER'), os.environ.get('NEO4J_PWD')))
summary = driver.execute_query('''
MERGE (n:project {project_name: $project})
''', project=project.get('name')).summary
driver.close()
nope, still the same. I use python 3.9 and im running it in a mac m1, if it rings any bell due to incompatibility
I don't have all the credits for the answer, but it seems that you didn't close your session, here is an AI powered fixed python code
driver = GraphDatabase.driver(os.environ.get('NEO4J_DB'),
auth=(os.environ.get('NEO4J_USER'), os.environ.get('NEO4J_PWD')))
with driver.session() as session:
session.run('''
MERGE (n:project {project_name: $project})
''', project=project.get('name'))
driver.close()
The with close your session automaticly and the driver is closed explicitly.
turns out the problem is with another library it was interfering with (click), that was weird. Im closing this anwyay
1 Like