py2neo 引发完成(自我)错误

2024-05-15

使用 py2neo 时,我在尝试附加事务时收到以下错误:

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)

回溯是:

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

有任何想法吗?


如果您调用 tx.commit() 两次而中间没有 tx = graph.cypher.begin() ,您将收到此错误。如果您试图对提交进行分块,这是一个很容易犯的错误。更明确地说:

 #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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

py2neo 引发完成(自我)错误 的相关文章

随机推荐