versae / neo4j-rest-client

Object-oriented Python library to interact with Neo4j standalone REST server
http://neo4j-rest-client.rtfd.org
GNU General Public License v3.0
264 stars 73 forks source link

Error when using a transaction #135

Open OrangeBoreal opened 7 years ago

OrangeBoreal commented 7 years ago

When committing or rolling back from a transaction, subsequent calls to the client result in a TransactionException :

from neo4jrestclient import client
import os
c = client.GraphDatabase(url=os.environ["NEO4J_URL"])
res = c.query("MATCH (n:Person) WHERE n.name = 'Carol' RETURN n") assert res.get_response()["data"][0][0]["data"] == {"name": "Carol"}

with c.transaction(for_query=True) as t:
    c.query("MATCH (n:Person) WHERE n.name = 'Carol' RETURN n")
    t.rollback()  # or commit()

c.query("MATCH (n:Person) WHERE n.name = 'Carol' RETURN n")
TransactionException                      Traceback (most recent call last)
<ipython-input-16-c750d86ca4cf> in <module>()
      9     t.commit()
     10 
---> 11 c.query("MATCH (n:Person) WHERE n.name = 'Carol' RETURN n")

.../code/neo4j-rest-client/neo4jrestclient/client.pyc in query(self, q, params, returns, data_contents, tx)
    210                 self._cypher, self._auth, q=q, params=params,
    211                 types=types, returns=returns, data_contents=data_contents,
--> 212                 tx=tx
    213             )
    214             if tx is not None and tx.id in self._transactions:

.../code/neo4j-rest-client/neo4jrestclient/query.pyc in __init__(self, cypher, auth, q, params, types, returns, lazy, data_contents, tx)
    322             tx.append(q=self.q, params=self.params, returns=self._returns,
    323                       data_contents=data_contents, obj=self)
--> 324             tx.execute()
    325         elif not lazy:
    326             self._get_elements()

.../code/neo4j-rest-client/neo4jrestclient/query.pyc in execute(self)
    937         if not self.url_tx:
    938             self._begin()
--> 939         results = self._execute(self.url_tx, results=True)
    940         self.finished = False
    941         return results

.../code/neo4j-rest-client/neo4jrestclient/query.pyc in _execute(self, url, results)
    863 
    864     def _execute(self, url, results=True):
--> 865         response = self._request(url, statements=self.statements)
    866         content = response.json()
    867         self._manage_errors(content["errors"])

.../code/neo4j-rest-client/neo4jrestclient/query.pyc in _request(self, url, statements)
    860             return response
    861         else:
--> 862             raise TransactionException(response.status_code)
    863 
    864     def _execute(self, url, results=True):

TransactionException: Code [404]: Not Found. Nothing matches the given URI.
Element not found

The client is completely block unless calling .flush()

versae commented 7 years ago

Sorry for the late reply. After rolling back the transaction gets destroyed, thus the 404. But then it should not try to execute any query. It seems like the local transaction is not destroyed. Have you tried not using the with statement?

OrangeBoreal commented 7 years ago

I've got the same issue, whether I'm using the context manager or not.