'Updating a node with merge using Py2Neo

I'm trying to merge and then update a graph using the py2neo library. My code looks roughly like

from py2neo import Graph, Node, Relationship

graph = Graph(host, auth=(user, password,))

tx = graph.begin()
alice = Node("Person", name="Alice")
bob = Node("Person", name="Bob")
KNOWS = Relationship(alice, "KNOWS", bob)
tx.create(KNOWS)
graph.commit(tx)

This creates the nodes and edges as expected as

(:Person {name: "Alice"})-[:KNOWS]->(:Person {name: "Bob"})

If I try to modify alice in a new transaction though, I get no change

e.g.

new_tx = graph.begin()
alice["age"] = 32
new_tx.merge(alice, "Person", "name")
graph.commit(new_tx)

I suspect I have misunderstood how the Transaction works here. I would expect the above to be equivalent to either finding Alice and updating with the new property or creating a new node.

Update: I have discovered the Graph.push method, but would still appreciate advice on best practice.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source