Skip to content

Commit 116d2c2

Browse files
committed
Update _finish_transaction()
Check if the session is ended, and always increment txnNumber.
1 parent 6671ee2 commit 116d2c2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pymongo/client_session.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,17 @@ def abort_transaction(self):
216216
self._finish_transaction("abortTransaction")
217217

218218
def _finish_transaction(self, command_name):
219+
self._check_ended()
220+
219221
if self._current_transaction_opts is None:
220222
raise InvalidOperation("No transaction started")
221223

222-
if self._server_session.statement_id == 0:
223-
# Not really started.
224-
return
225-
226224
try:
225+
if self._server_session.statement_id == 0:
226+
# Not really started.
227+
self._server_session._transaction_id += 1
228+
return
229+
227230
# TODO: retryable. And it's weird to pass parse_write_concern_error
228231
# from outside database.py.
229232
self._client.admin.command(

0 commit comments

Comments
 (0)