Skip to content

Commit def05fb

Browse files
authored
Merge pull request #247 from technige/1.7-replace-ack-failure-with-reset
Replaced ACK_FAILURE with RESET
2 parents d9de5bb + 442b3b6 commit def05fb

12 files changed

+22
-32
lines changed

neo4j/bolt/connection.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
from neo4j.addressing import SocketAddress, Resolver
3838
from neo4j.bolt.cert import KNOWN_HOSTS
39-
from neo4j.bolt.response import InitResponse, AckFailureResponse, ResetResponse
39+
from neo4j.bolt.response import InitResponse, ResetResponse
4040
from neo4j.compat.ssl import SSL_AVAILABLE, HAS_SNI, SSLError
4141
from neo4j.exceptions import ClientError, ProtocolError, SecurityError, ServiceUnavailable
4242
from neo4j.packstream import Packer, Unpacker
@@ -53,7 +53,6 @@
5353

5454
# Signature bytes for each message type
5555
INIT = b"\x01" # 0000 0001 // INIT <user_agent> <auth>
56-
ACK_FAILURE = b"\x0E" # 0000 1110 // ACK_FAILURE
5756
RESET = b"\x0F" # 0000 1111 // RESET
5857
RUN = b"\x10" # 0001 0000 // RUN <statement> <parameters>
5958
DISCARD_ALL = b"\x2F" # 0010 1111 // DISCARD *
@@ -240,8 +239,6 @@ def append(self, signature, fields=(), response=None):
240239
log_debug("C: DISCARD_ALL %r", fields)
241240
elif signature == RESET:
242241
log_debug("C: RESET %r", fields)
243-
elif signature == ACK_FAILURE:
244-
log_debug("C: ACK_FAILURE %r", fields)
245242
elif signature == INIT:
246243
log_debug("C: INIT (%r, {...})", fields[0])
247244
else:
@@ -251,13 +248,6 @@ def append(self, signature, fields=(), response=None):
251248
self.output_buffer.chunk()
252249
self.responses.append(response)
253250

254-
def acknowledge_failure(self):
255-
""" Add an ACK_FAILURE message to the outgoing queue, send
256-
it and consume all remaining messages.
257-
"""
258-
self.append(ACK_FAILURE, response=AckFailureResponse(self))
259-
self.sync()
260-
261251
def reset(self):
262252
""" Add a RESET message to the outgoing queue, send
263253
it and consume all remaining messages.

neo4j/bolt/response.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ def on_failure(self, metadata):
6363
raise ServiceUnavailable(message)
6464

6565

66-
class AckFailureResponse(Response):
67-
68-
def on_failure(self, metadata):
69-
raise ProtocolError("ACK_FAILURE failed")
70-
71-
7266
class ResetResponse(Response):
7367

7468
def on_failure(self, metadata):

neo4j/v1/api.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,19 @@ def rollback_transaction(self):
440440
"""
441441
if not self.has_transaction():
442442
raise TransactionError("No transaction to rollback")
443-
self._transaction = None
443+
self._destroy_transaction()
444444
rollback_result = self.__rollback__()
445445
try:
446446
rollback_result.consume()
447447
except ServiceUnavailable:
448448
pass
449449

450+
def reset(self):
451+
""" Reset the session.
452+
"""
453+
self._destroy_transaction()
454+
self._connection.reset()
455+
450456
def _run_transaction(self, access_mode, unit_of_work, *args, **kwargs):
451457
if not callable(unit_of_work):
452458
raise TypeError("Unit of work is not callable")
@@ -640,10 +646,11 @@ def close(self):
640646
self.success = False
641647
raise
642648
finally:
643-
if self.success:
644-
self.session.commit_transaction()
645-
else:
646-
self.session.rollback_transaction()
649+
if self.session.has_transaction():
650+
if self.success:
651+
self.session.commit_transaction()
652+
else:
653+
self.session.rollback_transaction()
647654
self._closed = True
648655
self.on_close()
649656

neo4j/v1/result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def on_footer(metadata):
6565

6666
def on_failure(metadata):
6767
# Called on execution failure.
68-
self.session._connection.acknowledge_failure()
68+
self.session.reset()
6969
on_footer(metadata)
7070
raise CypherError.hydrate(**metadata)
7171

test/integration/test_session.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,10 @@ def test_last_run_statement_should_be_cleared_on_failure(self):
357357
connection_1 = session._connection
358358
assert connection_1._last_run_statement == "RETURN 1"
359359
with self.assertRaises(CypherSyntaxError):
360-
tx.run("X").consume()
361-
connection_2 = session._connection
360+
result = tx.run("X")
361+
connection_2 = session._connection
362+
result.consume()
363+
# connection_2 = session._connection
362364
assert connection_2 is connection_1
363365
assert connection_2._last_run_statement is None
364366
tx.close()

test/stub/scripts/broken_router.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ C: RUN "CALL dbms.cluster.routing.getServers" {}
55
PULL_ALL
66
S: FAILURE {"code": "Neo.DatabaseError.General.UnknownError", "message": "An unknown error occurred."}
77
IGNORED
8-
C: ACK_FAILURE
8+
C: RESET
99
S: SUCCESS {}

test/stub/scripts/database_unavailable.script

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
!: AUTO INIT
22
!: AUTO RESET
33
!: AUTO PULL_ALL
4-
!: AUTO ACK_FAILURE
54
!: AUTO RUN "ROLLBACK" {}
65
!: AUTO RUN "BEGIN" {}
76
!: AUTO RUN "COMMIT" {}

test/stub/scripts/error_in_tx.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ C: RUN "X" {}
1111
S: FAILURE {"code": "Neo.ClientError.Statement.SyntaxError", "message": "X"}
1212
IGNORED {}
1313

14-
C: ACK_FAILURE
14+
C: RESET
1515
S: SUCCESS {}
1616

1717
C: RUN "ROLLBACK" {}

test/stub/scripts/forbidden_on_read_only_database.script

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
!: AUTO INIT
22
!: AUTO RESET
33
!: AUTO PULL_ALL
4-
!: AUTO ACK_FAILURE
54
!: AUTO RUN "ROLLBACK" {}
65
!: AUTO RUN "BEGIN" {}
76
!: AUTO RUN "COMMIT" {}

test/stub/scripts/non_router.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ C: RUN "CALL dbms.cluster.routing.getServers" {}
55
PULL_ALL
66
S: FAILURE {"code": "Neo.ClientError.Procedure.ProcedureNotFound", "message": "Not a router"}
77
IGNORED
8-
C: ACK_FAILURE
8+
C: RESET
99
S: SUCCESS {}

0 commit comments

Comments
 (0)