Search code examples
pythonneo4jpy2neo

Don't understand why this AttributeError: 'Graph' object has no attribute 'merge_one' is occurring


I'm following a tutorial, and I'm using the last python2 (homebrew) with PyCharm (with project interpreter configured) - But I'm stuck in this part:

from py2neo import Graph, Node
graph = Graph()
nicole = Node("Person", name="Nicole")
graph.create(nicole)
graph.delete(nicole)
nicole = graph.merge_one("Person", "name", "Nicole")

Error:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
AttributeError: 'Graph' object has no attribute 'merge_one'

I already checked the documentation and it seems that I'm doing everything ok . I tried to uninstall and install last version of py2neo but with no success. How I solve this problem?

Expected behavior: Running that command from the python2 console: If that Person exists don't duplicate it but change its values, if don't exist create it.


Solution

  • I fastly ended up using the version 4 as opposed to 2. So using Graph.merge, solved the problem:

    jonh = Node("Person", name="Jonh", age = 21)
    graph.create(jonh)
    ana = Node("Person", name="Ana", age = 44)
    graph.create(ana)
    michael = Node("Person", name="Ana", age = 33)
    graph.merge(michael, "Person", "name") # So the age of Ana will change to 33, as expected.
    

    For using the commands related to my question, the version 2 must be installed, for eg. directly from py2neo repo:

    pip install https://github.com/technige/py2neo/archive/release/2.0.7.zip