Skip to content

Commit 359ddfa

Browse files
authored
PYTHON-5741 - Transaction state is preserved across retries (#2718)
1 parent e7a5247 commit 359ddfa

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,15 +894,16 @@ def __init__(
894894
self._options.read_concern,
895895
)
896896

897+
self._retry_policy = _RetryPolicy(
898+
_TokenBucket(), adaptive_retry=self._options.adaptive_retries
899+
)
900+
897901
self._init_based_on_options(self._seeds, srv_max_hosts, srv_service_name)
898902

899903
self._opened = False
900904
self._closed = False
901905
self._loop: Optional[asyncio.AbstractEventLoop] = None
902906

903-
self._retry_policy = _RetryPolicy(
904-
_TokenBucket(), adaptive_retry=self._options.adaptive_retries
905-
)
906907
if not is_srv:
907908
self._init_background()
908909

pymongo/synchronous/mongo_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,15 +894,16 @@ def __init__(
894894
self._options.read_concern,
895895
)
896896

897+
self._retry_policy = _RetryPolicy(
898+
_TokenBucket(), adaptive_retry=self._options.adaptive_retries
899+
)
900+
897901
self._init_based_on_options(self._seeds, srv_max_hosts, srv_service_name)
898902

899903
self._opened = False
900904
self._closed = False
901905
self._loop: Optional[asyncio.AbstractEventLoop] = None
902906

903-
self._retry_policy = _RetryPolicy(
904-
_TokenBucket(), adaptive_retry=self._options.adaptive_retries
905-
)
906907
if not is_srv:
907908
self._init_background()
908909

test/transactions/unified/backpressure-retryable-writes.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,31 @@
412412
"events": [
413413
{
414414
"commandStartedEvent": {
415-
"commandName": "insert"
415+
"command": {
416+
"startTransaction": true
417+
},
418+
"commandName": "insert",
419+
"databaseName": "transaction-tests"
416420
}
417421
},
418422
{
419423
"commandStartedEvent": {
420-
"commandName": "insert"
424+
"command": {
425+
"startTransaction": true
426+
},
427+
"commandName": "insert",
428+
"databaseName": "transaction-tests"
421429
}
422430
},
423431
{
424432
"commandStartedEvent": {
425-
"commandName": "abortTransaction"
433+
"command": {
434+
"startTransaction": {
435+
"$$exists": false
436+
}
437+
},
438+
"commandName": "abortTransaction",
439+
"databaseName": "admin"
426440
}
427441
}
428442
]

0 commit comments

Comments
 (0)