Skip to content

Commit 108ad80

Browse files
committed
Bug fix to clear last statement on ignored/failure
1 parent de33b51 commit 108ad80

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

neo4j/bolt/connection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,15 @@ def fetch(self):
270270
log_info("S: SUCCESS (%r)", summary_metadata)
271271
response.on_success(summary_metadata or {})
272272
elif summary_signature == IGNORED:
273+
self._last_run_statement = None
273274
log_info("S: IGNORED (%r)", summary_metadata)
274275
response.on_ignored(summary_metadata or {})
275276
elif summary_signature == FAILURE:
277+
self._last_run_statement = None
276278
log_info("S: FAILURE (%r)", summary_metadata)
277279
response.on_failure(summary_metadata or {})
278280
else:
281+
self._last_run_statement = None
279282
raise ProtocolError("Unexpected response message with signature %02X" % summary_signature)
280283

281284
return len(details), 1

test/integration/test_session.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,19 @@ def test_broken_transaction_should_not_break_session(self):
347347
with session.begin_transaction() as tx:
348348
tx.run("RETURN 1")
349349

350+
def test_last_run_statement_should_be_cleared_on_failure(self):
351+
with self.driver.session() as session:
352+
tx = session.begin_transaction()
353+
tx.run("RETURN 1").consume()
354+
connection_1 = session._connection
355+
assert connection_1._last_run_statement == "RETURN 1"
356+
with self.assertRaises(CypherSyntaxError):
357+
tx.run("X").consume()
358+
connection_2 = session._connection
359+
assert connection_2 is connection_1
360+
assert connection_2._last_run_statement is None
361+
tx.close()
362+
350363

351364
class BookmarkingTestCase(DirectIntegrationTestCase):
352365

0 commit comments

Comments
 (0)