-
Notifications
You must be signed in to change notification settings - Fork 197
Connection.close() raises TypeError("'NoneType' object is not callable",)
#172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
@shispt As Nigel commented, the connection is not supposed to be used directly. Pls let use know if you have any error while driver, session or transaction public APIs. |
So, I get the same error message, and I'm not explicitly closing the connection. When my script finishes, this is auto-firing, apparently. Oddly, when I have a much longer running script, it doesn't happen. When I have a very short install validation script that invokes the same connection setup code, it happens every time. Exception TypeError: "'NoneType' object is not callable" in <bound method DirectDriver.del of <neo4j.v1.direct.DirectDriver object at 0x0000000008C1AEB8>> ignored |
I am having a similar error using the driver. I am running a program main.py with a class NeoGraph I have made. The following methods are presumably important to the issue: import neo4j
import networkx as nx
class NeoGraph(nx.DiGraph):
'''
Extended directional graph class from networkx, with added functionality for storing
into neo4j database, initializing from neo4j database.
'''
def __init__(self, uri: str, user: str, password: str, incoming_graph_data=None, **attr):
'''
Same as nx function declaration but also requires DB driver.
[self.driver] is to be a neo4j.GraphDatabase.driver to connect to the DB
Form: GraphDatabase.driver(uri=uri,auth=(user,password))
Therefore, init requires 3 additional positional args: uri, user, password
'''
self.driver = neo4j.GraphDatabase.driver(uri=uri, auth = (user, password))
nx.DiGraph.__init__(self, incoming_graph_data, **attr) #pass the rest to DiGraph's init
def close(self):
'''
Close out the DBMS connection.
'''
if self.driver:
self.driver.close()
def reopen(self):
'''
Reopen the DBMS connection if it is closed.
'''
self.driver = neo4j.GraphDatabase.driver(uri=uri, auth = (user, password))
def __del__(self):
if self.driver:
self.close()
super().__del__() In main.py I (successfully) initialize a NeoGraph object (named G), use it to do some things, and then the program exits. If I do work with the NeoGraph (read and/or write transactions), everything exits fine. If run the program as a script and I don't do any write transactions with my object, I get an ugly printout. Whether I manually run G.close() or allow garbage collection to automatically run G.__del__(), or even if I completely remove my deletion code to let Python do it's own thing, I get the following error: Exception ignored in: <function NeoGraph.del at 0x7fa7a8a693a0> This only happens when I don't use the python program for very long, and it doesn't happen if I run things in a notebook format. I am very confused what's going wrong, please help. Versions: |
Hi @danielfrees. What driver version is this? 5.0.1? |
@robsdedude Yep, just checked its 5.0.1 Edited my above comment for clarity. The issue only occurs when I don't use my NeoGraph object other than initializing it, and putting some data into it. If I do any write transactions everything runs fine. Also, I tried to manually add to the logging debug stream as another fix (since the traceback indicated something was going wrong with the log object), and still get an error, but with a slightly different Traceback: New code: # Set up logger
log = getLogger("neo4j")
#code in between.....
def close(self):
'''
Close out the DBMS connection.
'''
if self.driver:
log.debug(f'Closing neo4j cxn.')
self.driver.close()
self.driver.__del__() Traceback (most recent call last): |
My full code is at: https://github.com/danielfrees/neograph You can find the important functionality under neograph/nx_to_neo.py Just attaching this in case more details are needed to review this issue. Thanks :) |
Alright, so I had another look at it. I've never come across this particular error and I actually wasn't able to reproduce it.
I then tried this import neo4j
import networkx as nx
class NeoGraph(nx.DiGraph):
"""
Extended directional graph class from networkx, with added functionality for storing
into neo4j database, initializing from neo4j database.
"""
def __init__(self, uri: str, user: str, password: str, incoming_graph_data=None, **attr):
"""
Same as nx function declaration but also requires DB driver.
[self.driver] is to be a neo4j.GraphDatabase.driver to connect to the DB
Form: GraphDatabase.driver(uri=uri,auth=(user,password))
Therefore, init requires 3 additional positional args: uri, user, password
"""
self.driver = neo4j.GraphDatabase.driver(uri=uri, auth=(user, password))
nx.DiGraph.__init__(self, incoming_graph_data, **attr) #pass the rest to DiGraph's init
def close(self):
"""
Close out the DBMS connection.
"""
if self.driver:
self.driver.close()
def reopen(self, uri: str, user: str, password: str):
"""
Reopen the DBMS connection if it is closed.
"""
self.driver = neo4j.GraphDatabase.driver(uri=uri, auth=(user, password))
def __del__(self):
if self.driver:
self.close()
# super().__del__()
def main():
uri = "neo4j://localhost:7687"
user = "neo4j"
password = "pass"
ng = NeoGraph(uri, user, password)
del ng
import gc
gc.collect() # should't be necessary because no cyclic refs
if __name__ == "__main__":
main() Runs smoothly for me. Here are some thoughts:
|
After upgrading to 3.9.13, removing A couple quick questions, as I'm new to software dev in python:
Thanks again for all your help on this, I really appreciate it. Happy to have a script running without any long error outputs. |
|
when I run
python start.py
(python2.7, no errors with python3 ), got this error:my project structure:
start.py:
db.py:
I found while calling
close
method fromneo4j.bolt.connection.Connection
,log_info
isNone
.my version info
A similar case (saved as test.py):
The text was updated successfully, but these errors were encountered: