py2neo raised finished(self) error

妖精的绣舞 提交于 2019-12-23 19:09:44

问题


Working with py2neo and I'm getting the error below when trying to append a transaction:

statement ="MERGE (a:Person {name:\""+actorName+"\"}) "\
            "\n"\
            "MERGE (b:Series {title:\""+actorsFields[3]+"\", year:\""+actorsFields[5]+"\"}) "\
            "\n"\
            "CREATE UNIQUE (a)-[:ACTED_IN]->(b)"\
            "RETURN a,b"
print(statement)
tx.append(statement)

The traceback is:

Traceback (most recent call last):
  File "/Volumes/PyCharm CE/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 2222, in <module>
    globals = debugger.run(setup['file'], None, None)
  File "/Volumes/PyCharm CE/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1648, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/Thibault/PycharmProjects/movieGraph/src/mainCypher.py", line 110, in <module>
    tx.append(statement)
  File "/Library/Python/2.7/site-packages/py2neo/cypher/core.py", line 220, in append
    self.__assert_unfinished()
  File "/Library/Python/2.7/site-packages/py2neo/cypher/core.py", line 192, in __assert_unfinished
    raise Finished(self)
py2neo.error.Finished

any ideas?


回答1:


You will get this error if you call tx.commit() twice without a tx = graph.cypher.begin() in between. This is an easy mistake to make if you are trying to chunk your commits. To be more explicit:

 #This will give the above error
 tx = graph.cypher.begin()
 for i in range(0,10):
      tx.append(statement="foo",parameters=bar)
      tx.commit()

 #This will work fine
 for i in range(0,10):
      tx = graph.cypher.begin()
      tx.append(statement="foo",parameters=bar)
      tx.commit()


来源:https://stackoverflow.com/questions/29162160/py2neo-raised-finishedself-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!