Skip to content

Commit 5170d81

Browse files
authored
Merge branch 'master' into dependabot/pip/mypy-1.19.1
2 parents 5f342f9 + 0cfba49 commit 5170d81

40 files changed

+1671
-92
lines changed

.github/workflows/codeql.yml

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

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v4
49+
uses: github/codeql-action/init@1b168cd39490f61582a9beae412bb7057a6b2c4e # 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@cf1bb45a277cb3c205638b2cd5c984db1c46a412 # v4
66+
uses: github/codeql-action/analyze@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4
6767
with:
6868
category: "/language:${{matrix.language}}"

.github/workflows/dist.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
# Free-threading builds:
9292
ls wheelhouse/*cp314t*.whl
9393
94-
- uses: actions/upload-artifact@v5
94+
- uses: actions/upload-artifact@v6
9595
with:
9696
name: wheel-${{ matrix.buildplat[1] }}
9797
path: ./wheelhouse/*.whl
@@ -124,7 +124,7 @@ jobs:
124124
cd ..
125125
python -c "from pymongo import has_c; assert has_c()"
126126
127-
- uses: actions/upload-artifact@v5
127+
- uses: actions/upload-artifact@v6
128128
with:
129129
name: "sdist"
130130
path: ./dist/*.tar.gz
@@ -135,13 +135,13 @@ jobs:
135135
name: Download Wheels
136136
steps:
137137
- name: Download all workflow run artifacts
138-
uses: actions/download-artifact@v6
138+
uses: actions/download-artifact@v7
139139
- name: Flatten directory
140140
working-directory: .
141141
run: |
142142
find . -mindepth 2 -type f -exec mv {} . \;
143143
find . -type d -empty -delete
144-
- uses: actions/upload-artifact@v5
144+
- uses: actions/upload-artifact@v6
145145
with:
146146
name: all-dist-${{ github.run_id }}
147147
path: "./*"

.github/workflows/release-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
id-token: write
7676
steps:
7777
- name: Download all the dists
78-
uses: actions/download-artifact@v6
78+
uses: actions/download-artifact@v7
7979
with:
8080
name: all-dist-${{ github.run_id }}
8181
path: dist/

.github/workflows/sbom.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ jobs:
6363
run: rm -rf .venv .venv-sbom
6464

6565
- name: Upload SBOM artifact
66-
uses: actions/upload-artifact@v5
66+
uses: actions/upload-artifact@v6
6767
with:
6868
name: sbom
6969
path: sbom.json
7070
if-no-files-found: error
7171

7272
- name: Create Pull Request
73-
uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676
73+
uses: peter-evans/create-pull-request@98357b18bf14b5342f975ff684046ec3b2a07725
7474
with:
7575
token: ${{ secrets.GITHUB_TOKEN }}
7676
commit-message: 'chore: Update SBOM after dependency changes'

.github/workflows/test-python.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
persist-credentials: false
2828
- name: Install uv
29-
uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7
29+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7
3030
with:
3131
enable-cache: true
3232
python-version: "3.10"
@@ -68,7 +68,7 @@ jobs:
6868
with:
6969
persist-credentials: false
7070
- name: Install uv
71-
uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7
71+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7
7272
with:
7373
enable-cache: true
7474
python-version: ${{ matrix.python-version }}
@@ -87,7 +87,7 @@ jobs:
8787
with:
8888
persist-credentials: false
8989
- name: Install uv
90-
uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7
90+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7
9191
with:
9292
enable-cache: true
9393
python-version: "3.10"
@@ -112,7 +112,7 @@ jobs:
112112
with:
113113
persist-credentials: false
114114
- name: Install uv
115-
uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7
115+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7
116116
with:
117117
enable-cache: true
118118
python-version: "3.10"
@@ -131,7 +131,7 @@ jobs:
131131
with:
132132
persist-credentials: false
133133
- name: Install uv
134-
uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7
134+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7
135135
with:
136136
enable-cache: true
137137
python-version: "3.10"
@@ -153,7 +153,7 @@ jobs:
153153
with:
154154
persist-credentials: false
155155
- name: Install uv
156-
uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7
156+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7
157157
with:
158158
enable-cache: true
159159
python-version: "${{matrix.python}}"
@@ -174,7 +174,7 @@ jobs:
174174
with:
175175
persist-credentials: false
176176
- name: Install uv
177-
uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7
177+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7
178178
with:
179179
enable-cache: true
180180
python-version: "3.10"
@@ -214,7 +214,7 @@ jobs:
214214
run: |
215215
pip install build
216216
python -m build --sdist
217-
- uses: actions/upload-artifact@v5
217+
- uses: actions/upload-artifact@v6
218218
with:
219219
name: "sdist"
220220
path: dist/*.tar.gz
@@ -226,7 +226,7 @@ jobs:
226226
timeout-minutes: 20
227227
steps:
228228
- name: Download sdist
229-
uses: actions/download-artifact@v6
229+
uses: actions/download-artifact@v7
230230
with:
231231
path: sdist/
232232
- name: Unpack SDist
@@ -264,7 +264,7 @@ jobs:
264264
with:
265265
persist-credentials: false
266266
- name: Install uv
267-
uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7
267+
uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7
268268
with:
269269
python-version: "3.10"
270270
- id: setup-mongodb

.github/workflows/zizmor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
with:
1919
persist-credentials: false
2020
- name: Run zizmor 🌈
21-
uses: zizmorcore/zizmor-action@c0e2b1c877e25a91d1d747c438d49199cad29698
21+
uses: zizmorcore/zizmor-action@cb3d8e846e148d1111d90b03375b9c03deceda37

pymongo/asynchronous/mongo_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2825,7 +2825,7 @@ async def run(self) -> T:
28252825
if self._last_error is None:
28262826
self._last_error = exc
28272827

2828-
if self._client.topology_description.topology_type == TOPOLOGY_TYPE.Sharded:
2828+
if self._server is not None:
28292829
self._deprioritized_servers.append(self._server)
28302830

28312831
def _is_not_eligible_for_retry(self) -> bool:

pymongo/asynchronous/topology.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ async def select_servers(
268268
server_selection_timeout: Optional[float] = None,
269269
address: Optional[_Address] = None,
270270
operation_id: Optional[int] = None,
271+
deprioritized_servers: Optional[list[Server]] = None,
271272
) -> list[Server]:
272273
"""Return a list of Servers matching selector, or time out.
273274
@@ -295,7 +296,12 @@ async def select_servers(
295296

296297
async with self._lock:
297298
server_descriptions = await self._select_servers_loop(
298-
selector, server_timeout, operation, operation_id, address
299+
selector,
300+
server_timeout,
301+
operation,
302+
operation_id,
303+
address,
304+
deprioritized_servers=deprioritized_servers,
299305
)
300306

301307
return [
@@ -309,6 +315,7 @@ async def _select_servers_loop(
309315
operation: str,
310316
operation_id: Optional[int],
311317
address: Optional[_Address],
318+
deprioritized_servers: Optional[list[Server]] = None,
312319
) -> list[ServerDescription]:
313320
"""select_servers() guts. Hold the lock when calling this."""
314321
now = time.monotonic()
@@ -327,7 +334,12 @@ async def _select_servers_loop(
327334
)
328335

329336
server_descriptions = self._description.apply_selector(
330-
selector, address, custom_selector=self._settings.server_selector
337+
selector,
338+
address,
339+
custom_selector=self._settings.server_selector,
340+
deprioritized_servers=[server.description for server in deprioritized_servers]
341+
if deprioritized_servers
342+
else None,
331343
)
332344

333345
while not server_descriptions:
@@ -388,9 +400,13 @@ async def _select_server(
388400
operation_id: Optional[int] = None,
389401
) -> Server:
390402
servers = await self.select_servers(
391-
selector, operation, server_selection_timeout, address, operation_id
403+
selector,
404+
operation,
405+
server_selection_timeout,
406+
address,
407+
operation_id,
408+
deprioritized_servers,
392409
)
393-
servers = _filter_servers(servers, deprioritized_servers)
394410
if len(servers) == 1:
395411
return servers[0]
396412
server1, server2 = random.sample(servers, 2)
@@ -1119,16 +1135,3 @@ def _is_stale_server_description(current_sd: ServerDescription, new_sd: ServerDe
11191135
if current_tv["processId"] != new_tv["processId"]:
11201136
return False
11211137
return current_tv["counter"] > new_tv["counter"]
1122-
1123-
1124-
def _filter_servers(
1125-
candidates: list[Server], deprioritized_servers: Optional[list[Server]] = None
1126-
) -> list[Server]:
1127-
"""Filter out deprioritized servers from a list of server candidates."""
1128-
if not deprioritized_servers:
1129-
return candidates
1130-
1131-
filtered = [server for server in candidates if server not in deprioritized_servers]
1132-
1133-
# If not possible to pick a prioritized server, return the original list
1134-
return filtered or candidates

pymongo/server_selectors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ class Selection:
3434

3535
@classmethod
3636
def from_topology_description(cls, topology_description: TopologyDescription) -> Selection:
37-
known_servers = topology_description.known_servers
37+
candidate_servers = topology_description.candidate_servers
3838
primary = None
39-
for sd in known_servers:
39+
for sd in candidate_servers:
4040
if sd.server_type == SERVER_TYPE.RSPrimary:
4141
primary = sd
4242
break
4343

4444
return Selection(
4545
topology_description,
46-
topology_description.known_servers,
46+
topology_description.candidate_servers,
4747
topology_description.common_wire_version,
4848
primary,
4949
)

pymongo/synchronous/mongo_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2815,7 +2815,7 @@ def run(self) -> T:
28152815
if self._last_error is None:
28162816
self._last_error = exc
28172817

2818-
if self._client.topology_description.topology_type == TOPOLOGY_TYPE.Sharded:
2818+
if self._server is not None:
28192819
self._deprioritized_servers.append(self._server)
28202820

28212821
def _is_not_eligible_for_retry(self) -> bool:

0 commit comments

Comments
 (0)