Skip to content

Commit cda4ff7

Browse files
committed
fix logic
1 parent 816632a commit cda4ff7

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,7 +2819,11 @@ async def run(self) -> T:
28192819

28202820
# Revert back to starting state if we're in a transaction but haven't completed the first
28212821
# command.
2822-
if self._session is not None and self._session.in_transaction:
2822+
if (
2823+
overloaded
2824+
and self._session is not None
2825+
and self._session.in_transaction
2826+
):
28232827
if not self._session._transaction.has_completed_command:
28242828
self._session._transaction.set_starting()
28252829
else:
@@ -2859,7 +2863,7 @@ async def run(self) -> T:
28592863
self._last_error = exc
28602864
# Revert back to starting state if we're in a transaction but haven't completed the first
28612865
# command.
2862-
if self._session is not None and self._session.in_transaction:
2866+
if overloaded and self._session is not None and self._session.in_transaction:
28632867
if not self._session._transaction.has_completed_command:
28642868
self._session._transaction.set_starting()
28652869

pymongo/synchronous/mongo_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,11 @@ def run(self) -> T:
28092809

28102810
# Revert back to starting state if we're in a transaction but haven't completed the first
28112811
# command.
2812-
if self._session is not None and self._session.in_transaction:
2812+
if (
2813+
overloaded
2814+
and self._session is not None
2815+
and self._session.in_transaction
2816+
):
28132817
if not self._session._transaction.has_completed_command:
28142818
self._session._transaction.set_starting()
28152819
else:
@@ -2849,7 +2853,7 @@ def run(self) -> T:
28492853
self._last_error = exc
28502854
# Revert back to starting state if we're in a transaction but haven't completed the first
28512855
# command.
2852-
if self._session is not None and self._session.in_transaction:
2856+
if overloaded and self._session is not None and self._session.in_transaction:
28532857
if not self._session._transaction.has_completed_command:
28542858
self._session._transaction.set_starting()
28552859

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@
238238
"client": "client0",
239239
"failPoint": {
240240
"configureFailPoint": "failCommand",
241-
"mode": {
242-
"times": 5
243-
},
241+
"mode": "alwaysOn",
244242
"data": {
245243
"failCommands": [
246244
"commitTransaction"
@@ -277,7 +275,10 @@
277275
},
278276
{
279277
"object": "session0",
280-
"name": "commitTransaction"
278+
"name": "commitTransaction",
279+
"expectError": {
280+
"isError": true
281+
}
281282
}
282283
],
283284
"expectEvents": [
@@ -367,11 +368,7 @@
367368
{
368369
"collectionName": "test",
369370
"databaseName": "transaction-tests",
370-
"documents": [
371-
{
372-
"_id": 1
373-
}
374-
]
371+
"documents": []
375372
}
376373
]
377374
}

0 commit comments

Comments
 (0)