Search code examples
pythondockerflaskneo4jpy2neo

Py2neo updateing existing node


I've been trying to update an existing node using py2neo. Some things worth metionioning:

OS: Arch Linux x86_64
python version: 3.8
py2neo version: 2021.0.1
ne4j version: 4.2.1
flask version: 1.1.2
Application is running inside a docker container, the actual flask website is on port 5000, neo4j interface is on port 7474 and flask connects to port 7687 (neo4j)

Here are a few methods I've tried:

1)

def update_node(self, node_name: str, node_group: str, property_update: dict):
    return self.name_search_person(node_name=node_name, node_group=node_group).update(**property_update)
def update_node(self, node_name: str, node_group: str, property_update: dict):
        node_to_update = self.name_search_person(node_name=node_name, node_group=node_group)
        if node_to_update:
            node_to_update.update(**property_update)
            self.g.push(node_to_update)
        del node_to_update
        return 'successfully updated node'

At the 2nd method I've tried with the following function calls:

graph_db.update_node(node_name='Andrei', node_group='Person', property_update={'name': t['Updated']})

(this just returns NameErrror: name 't' is not defined (I've seen this Here)

and

graph_db.update_node(node_name='Andrei', node_group='Person', property_update={'name':'Updated'})

Am I doing something wrong with the function calls or is the actual updating function not working by some reason?


Solution

  • Apparently the solution was to just remove the 't' from the function call

    graph_db.update_node(node_name='Andrei', node_group='Person', property_update={'name': t['Updated']}

    so now it's:

    graph_db.update_node(node_name='Andrei', node_group='Person', property_update={'name': ['Updated']}
    

    Honestly IDK why it didn't work with the other function call