Skip to content

Commit ce1b47c

Browse files
authored
Merge branch 'master' into PYTHON-5782
2 parents 8819c05 + 3405791 commit ce1b47c

24 files changed

Lines changed: 95 additions & 68 deletions

.evergreen/remove-unimplemented-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
22
PYMONGO=$(dirname "$(cd "$(dirname "$0")" || exit; pwd)")
33

4-
rm $PYMONGO/test/transactions/legacy/errors-client.json # PYTHON-1894
54
rm $PYMONGO/test/connection_monitoring/wait-queue-fairness.json # PYTHON-1873
65
rm $PYMONGO/test/discovery_and_monitoring/unified/pool-clear-application-error.json # PYTHON-4918
76
rm $PYMONGO/test/discovery_and_monitoring/unified/pool-clear-checkout-error.json # PYTHON-4918

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ jobs:
3838
build-mode: none
3939
steps:
4040
- name: Checkout repository
41-
uses: actions/checkout@v6.0.2
41+
uses: actions/checkout@v6.0.3
4242
with:
4343
ref: ${{ inputs.ref }}
4444
persist-credentials: false
4545
- uses: actions/setup-python@v6
4646

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@7211b7c8077ea37d8641b6271f6a365a22a5fbfa # v4
49+
uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4
5050
with:
5151
languages: ${{ matrix.language }}
5252
build-mode: ${{ matrix.build-mode }}
@@ -63,6 +63,6 @@ jobs:
6363
pip install -e .
6464
6565
- name: Perform CodeQL Analysis
66-
uses: github/codeql-action/analyze@7211b7c8077ea37d8641b6271f6a365a22a5fbfa # v4
66+
uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4
6767
with:
6868
category: "/language:${{matrix.language}}"

.github/workflows/dist.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
steps:
4848
- name: Checkout pymongo
49-
uses: actions/checkout@v6.0.2
49+
uses: actions/checkout@v6.0.3
5050
with:
5151
fetch-depth: 0
5252
persist-credentials: false
@@ -105,7 +105,7 @@ jobs:
105105
name: Make SDist
106106
runs-on: macos-latest
107107
steps:
108-
- uses: actions/checkout@v6.0.2
108+
- uses: actions/checkout@v6.0.3
109109
with:
110110
fetch-depth: 0
111111
persist-credentials: false

.github/workflows/sbom.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929

3030
steps:
3131
- name: Checkout repository
32-
uses: actions/checkout@v6.0.2
32+
uses: actions/checkout@v6.0.3
3333
with:
3434
persist-credentials: false
3535

.github/workflows/test-python.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ jobs:
2222
static:
2323
runs-on: ubuntu-latest
2424
steps:
25-
- uses: actions/checkout@v6.0.2
25+
- uses: actions/checkout@v6.0.3
2626
with:
2727
persist-credentials: false
2828
- name: Install uv
29-
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
29+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
3030
with:
3131
enable-cache: true
3232
python-version: "3.10"
@@ -64,11 +64,11 @@ jobs:
6464

6565
name: Python ${{ matrix.python-version }}-${{ matrix.os }}
6666
steps:
67-
- uses: actions/checkout@v6.0.2
67+
- uses: actions/checkout@v6.0.3
6868
with:
6969
persist-credentials: false
7070
- name: Install uv
71-
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
71+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
7272
with:
7373
enable-cache: true
7474
python-version: ${{ matrix.python-version }}
@@ -86,11 +86,11 @@ jobs:
8686

8787
name: Coverage
8888
steps:
89-
- uses: actions/checkout@v6.0.2
89+
- uses: actions/checkout@v6.0.3
9090
with:
9191
persist-credentials: false
9292
- name: Install uv
93-
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
93+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
9494
with:
9595
enable-cache: true
9696
python-version: "3.10"
@@ -114,11 +114,11 @@ jobs:
114114
runs-on: ubuntu-latest
115115
name: DocTest
116116
steps:
117-
- uses: actions/checkout@v6.0.2
117+
- uses: actions/checkout@v6.0.3
118118
with:
119119
persist-credentials: false
120120
- name: Install uv
121-
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
121+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
122122
with:
123123
enable-cache: true
124124
python-version: "3.10"
@@ -139,11 +139,11 @@ jobs:
139139
name: Docs Checks
140140
runs-on: ubuntu-latest
141141
steps:
142-
- uses: actions/checkout@v6.0.2
142+
- uses: actions/checkout@v6.0.3
143143
with:
144144
persist-credentials: false
145145
- name: Install uv
146-
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
146+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
147147
with:
148148
enable-cache: true
149149
python-version: "3.10"
@@ -158,11 +158,11 @@ jobs:
158158
name: Link Check
159159
runs-on: ubuntu-latest
160160
steps:
161-
- uses: actions/checkout@v6.0.2
161+
- uses: actions/checkout@v6.0.3
162162
with:
163163
persist-credentials: false
164164
- name: Install uv
165-
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
165+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
166166
with:
167167
enable-cache: true
168168
python-version: "3.10"
@@ -182,11 +182,11 @@ jobs:
182182
matrix:
183183
python: ["3.10", "3.11"]
184184
steps:
185-
- uses: actions/checkout@v6.0.2
185+
- uses: actions/checkout@v6.0.3
186186
with:
187187
persist-credentials: false
188188
- name: Install uv
189-
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
189+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
190190
with:
191191
enable-cache: true
192192
python-version: "${{matrix.python}}"
@@ -203,11 +203,11 @@ jobs:
203203
runs-on: ubuntu-latest
204204
name: Integration Tests
205205
steps:
206-
- uses: actions/checkout@v6.0.2
206+
- uses: actions/checkout@v6.0.3
207207
with:
208208
persist-credentials: false
209209
- name: Install uv
210-
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
210+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
211211
with:
212212
enable-cache: true
213213
python-version: "3.10"
@@ -233,7 +233,7 @@ jobs:
233233
runs-on: ubuntu-latest
234234
name: "Make an sdist"
235235
steps:
236-
- uses: actions/checkout@v6.0.2
236+
- uses: actions/checkout@v6.0.3
237237
with:
238238
persist-credentials: false
239239
- uses: actions/setup-python@v6
@@ -293,11 +293,11 @@ jobs:
293293
runs-on: ubuntu-latest
294294
name: Test minimum dependencies and Python
295295
steps:
296-
- uses: actions/checkout@v6.0.2
296+
- uses: actions/checkout@v6.0.3
297297
with:
298298
persist-credentials: false
299299
- name: Install uv
300-
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
300+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
301301
with:
302302
python-version: "3.9"
303303
- id: setup-mongodb

.github/workflows/zizmor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
security-events: write
1515
steps:
1616
- name: Checkout repository
17-
uses: actions/checkout@v6.0.2
17+
uses: actions/checkout@v6.0.3
1818
with:
1919
persist-credentials: false
2020
- name: Run zizmor 🌈

pymongo/asynchronous/bulk.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
from bson.objectid import ObjectId
3737
from bson.raw_bson import RawBSONDocument
3838
from pymongo import _csot, common
39-
from pymongo.asynchronous.client_session import AsyncClientSession, _validate_session_write_concern
39+
from pymongo.asynchronous.client_session import (
40+
AsyncClientSession,
41+
_validate_session_write_concern,
42+
)
4043
from pymongo.asynchronous.helpers import _handle_reauth
4144
from pymongo.bulk_shared import (
4245
_COMMANDS,
@@ -271,6 +274,8 @@ async def write_command(
271274
if bwc.publish:
272275
bwc._start(cmd, request_id, docs)
273276
try:
277+
if bwc.session is not None and bwc.session._starting_transaction:
278+
bwc.session._transaction.set_in_progress()
274279
reply = await bwc.conn.write_command(request_id, msg, bwc.codec) # type: ignore[misc]
275280
duration = datetime.datetime.now() - bwc.start_time
276281
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):

pymongo/asynchronous/client_bulk.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
from bson.objectid import ObjectId
3636
from bson.raw_bson import RawBSONDocument
3737
from pymongo import _csot, common
38-
from pymongo.asynchronous.client_session import AsyncClientSession, _validate_session_write_concern
38+
from pymongo.asynchronous.client_session import (
39+
AsyncClientSession,
40+
_validate_session_write_concern,
41+
)
3942
from pymongo.asynchronous.collection import AsyncCollection
4043
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
4144
from pymongo.asynchronous.database import AsyncDatabase
@@ -258,6 +261,8 @@ async def write_command(
258261
if bwc.publish:
259262
bwc._start(cmd, request_id, op_docs, ns_docs)
260263
try:
264+
if bwc.session is not None and bwc.session._starting_transaction:
265+
bwc.session._transaction.set_in_progress()
261266
reply = await bwc.conn.write_command(request_id, msg, bwc.codec) # type: ignore[misc, arg-type]
262267
duration = datetime.datetime.now() - bwc.start_time
263268
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):

pymongo/asynchronous/client_session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ def starting(self) -> bool:
443443
def set_starting(self) -> None:
444444
self.state = _TxnState.STARTING
445445

446+
def set_in_progress(self) -> None:
447+
if self.state == _TxnState.STARTING:
448+
self.state = _TxnState.IN_PROGRESS
449+
446450
@property
447451
def pinned_conn(self) -> Optional[AsyncConnection]:
448452
if self.active() and self.conn_mgr:
@@ -1135,7 +1139,6 @@ def _apply_to(
11351139

11361140
if self._transaction.state == _TxnState.STARTING:
11371141
# First command begins a new transaction.
1138-
self._transaction.state = _TxnState.IN_PROGRESS
11391142
command["startTransaction"] = True
11401143

11411144
assert self._transaction.opts

pymongo/asynchronous/mongo_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,8 +2870,8 @@ async def run(self) -> T:
28702870
self._last_error = exc
28712871
self._attempt_number += 1
28722872

2873-
# Revert back to starting state if we're in a transaction but haven't completed the first
2874-
# command.
2873+
# Revert back to starting state only if the first
2874+
# transactional command was never completed.
28752875
if (
28762876
overloaded
28772877
and self._session is not None
@@ -2921,8 +2921,8 @@ async def run(self) -> T:
29212921
self._last_error = exc
29222922
if self._last_error is None:
29232923
self._last_error = exc
2924-
# Revert back to starting state if we're in a transaction but haven't completed the first
2925-
# command.
2924+
# Revert back to starting state only if the first
2925+
# transactional command was never completed.
29262926
if overloaded and self._session is not None and self._session.in_transaction:
29272927
transaction = self._session._transaction
29282928
if not transaction.has_completed_command:

0 commit comments

Comments
 (0)