Skip to content

Commit 4926c3a

Browse files
committed
Fix transactions tests
1 parent 95d8f5f commit 4926c3a

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

pymongo/asynchronous/mongo_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,10 +2868,11 @@ async def run(self) -> T:
28682868
retryable_write_label = exc_to_check.has_error_label("RetryableWriteError")
28692869
overloaded = exc_to_check.has_error_label("SystemOverloadedError")
28702870
always_retryable = exc_to_check.has_error_label("RetryableError") and overloaded
2871-
if (
2872-
not self._client.options.retry_writes
2873-
or not self._retryable
2874-
and not always_retryable
2871+
2872+
# Always retry abortTransaction and commitTransaction up to once
2873+
if not (self._client.options.retry_writes and self._retryable) and (
2874+
not always_retryable
2875+
and self._operation not in ["abortTransaction", "commitTransaction"]
28752876
):
28762877
raise
28772878
if retryable_write_label or always_retryable:

pymongo/synchronous/mongo_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,10 +2858,11 @@ def run(self) -> T:
28582858
retryable_write_label = exc_to_check.has_error_label("RetryableWriteError")
28592859
overloaded = exc_to_check.has_error_label("SystemOverloadedError")
28602860
always_retryable = exc_to_check.has_error_label("RetryableError") and overloaded
2861-
if (
2862-
not self._client.options.retry_writes
2863-
or not self._retryable
2864-
and not always_retryable
2861+
2862+
# Always retry abortTransaction and commitTransaction up to once
2863+
if not (self._client.options.retry_writes and self._retryable) and (
2864+
not always_retryable
2865+
and self._operation not in ["abortTransaction", "commitTransaction"]
28652866
):
28662867
raise
28672868
if retryable_write_label or always_retryable:

0 commit comments

Comments
 (0)