Skip to content

Commit 6696778

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver
2 parents ed3a974 + 222a55f commit 6696778

File tree

14 files changed

+351
-176
lines changed

14 files changed

+351
-176
lines changed

.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@v5
41+
uses: actions/checkout@v6
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@0499de31b99561a6d14a36a5f662c2a54f91beee # v4
49+
uses: github/codeql-action/init@fdbfb4d2750291e159f0156def62b853c2798ca2 # 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@0499de31b99561a6d14a36a5f662c2a54f91beee # v4
66+
uses: github/codeql-action/analyze@fdbfb4d2750291e159f0156def62b853c2798ca2 # 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@v5
49+
uses: actions/checkout@v6
5050
with:
5151
fetch-depth: 0
5252
persist-credentials: false
@@ -101,7 +101,7 @@ jobs:
101101
name: Make SDist
102102
runs-on: macos-latest
103103
steps:
104-
- uses: actions/checkout@v5
104+
- uses: actions/checkout@v6
105105
with:
106106
fetch-depth: 0
107107
persist-credentials: false

.github/workflows/sbom.yml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Generate SBOM
22

3-
# This workflow uses cdxgen and publishes an sbom.json artifact.
3+
# This workflow uses cyclonedx-py and publishes an sbom.json artifact.
44
# It runs on manual trigger or when package files change on main branch,
55
# and creates a PR with the updated SBOM.
66
# Internal documentation: go/sbom-scope
@@ -27,12 +27,12 @@ jobs:
2727

2828
steps:
2929
- name: Checkout repository
30-
uses: actions/checkout@v4
30+
uses: actions/checkout@v6
3131
with:
3232
persist-credentials: false
3333

3434
- name: Set up Python
35-
uses: actions/setup-python@v5
35+
uses: actions/setup-python@v6
3636
with:
3737
python-version: "3.10"
3838

@@ -42,19 +42,36 @@ jobs:
4242
source .venv/bin/activate
4343
pip install -r requirements.txt
4444
pip install .
45-
npx @cyclonedx/cdxgen -t python --exclude "uv.lock" --exclude "requirements/**" --exclude "requirements.txt" --spec-version 1.5 --no-validate --json-pretty -o sbom.json
46-
env:
47-
FETCH_LICENSE: true
45+
pip uninstall -y pip setuptools
46+
deactivate
47+
python -m venv .venv-sbom
48+
source .venv-sbom/bin/activate
49+
pip install cyclonedx-bom==7.2.1
50+
cyclonedx-py environment --spec-version 1.5 --output-format JSON --output-file sbom.json .venv
51+
# Add PURL for pymongo (local package doesn't get PURL automatically)
52+
jq '(.components[] | select(.name == "pymongo" and .purl == null)) |= (. + {purl: ("pkg:pypi/pymongo@" + .version)})' sbom.json > sbom.tmp.json && mv sbom.tmp.json sbom.json
53+
54+
- name: Download CycloneDX CLI
55+
run: |
56+
curl -L -s -o /tmp/cyclonedx "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v0.29.1/cyclonedx-linux-x64"
57+
chmod +x /tmp/cyclonedx
58+
59+
- name: Validate SBOM
60+
run: /tmp/cyclonedx validate --input-file sbom.json --fail-on-errors
61+
62+
- name: Cleanup
63+
if: always()
64+
run: rm -rf .venv .venv-sbom
4865

4966
- name: Upload SBOM artifact
50-
uses: actions/upload-artifact@v4
67+
uses: actions/upload-artifact@v5
5168
with:
5269
name: sbom
5370
path: sbom.json
5471
if-no-files-found: error
5572

5673
- name: Create Pull Request
57-
uses: peter-evans/create-pull-request@b4733b9419fd47bbfa1807b15627e17cd70b5b22
74+
uses: peter-evans/create-pull-request@84ae59a2cdc2258d6fa0732dd66352dddae2a412
5875
with:
5976
token: ${{ secrets.GITHUB_TOKEN }}
6077
commit-message: 'chore: Update SBOM after dependency changes'
@@ -70,7 +87,7 @@ jobs:
7087
- Updated `sbom.json` to reflect current dependencies
7188

7289
### Verification
73-
The SBOM was generated using cdxgen with the current Python environment.
90+
The SBOM was generated using cyclonedx-py v7.2.1 with the current Python environment.
7491

7592
### Triggered by
7693
- Commit: ${{ github.sha }}
@@ -82,7 +99,3 @@ jobs:
8299
sbom
83100
automated
84101
dependencies
85-
86-
- name: Cleanup
87-
if: always()
88-
run: rm -rf .venv

.github/workflows/test-python.yml

Lines changed: 17 additions & 17 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@v5
25+
- uses: actions/checkout@v6
2626
with:
2727
persist-credentials: false
2828
- name: Install uv
29-
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7
29+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7
3030
with:
3131
enable-cache: true
3232
python-version: "3.10"
@@ -64,11 +64,11 @@ jobs:
6464

6565
name: CPython ${{ matrix.python-version }}-${{ matrix.os }}
6666
steps:
67-
- uses: actions/checkout@v5
67+
- uses: actions/checkout@v6
6868
with:
6969
persist-credentials: false
7070
- name: Install uv
71-
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7
71+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7
7272
with:
7373
enable-cache: true
7474
python-version: ${{ matrix.python-version }}
@@ -83,11 +83,11 @@ jobs:
8383
runs-on: ubuntu-latest
8484
name: DocTest
8585
steps:
86-
- uses: actions/checkout@v5
86+
- uses: actions/checkout@v6
8787
with:
8888
persist-credentials: false
8989
- name: Install uv
90-
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7
90+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7
9191
with:
9292
enable-cache: true
9393
python-version: "3.10"
@@ -108,11 +108,11 @@ jobs:
108108
name: Docs Checks
109109
runs-on: ubuntu-latest
110110
steps:
111-
- uses: actions/checkout@v5
111+
- uses: actions/checkout@v6
112112
with:
113113
persist-credentials: false
114114
- name: Install uv
115-
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7
115+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7
116116
with:
117117
enable-cache: true
118118
python-version: "3.10"
@@ -127,11 +127,11 @@ jobs:
127127
name: Link Check
128128
runs-on: ubuntu-latest
129129
steps:
130-
- uses: actions/checkout@v5
130+
- uses: actions/checkout@v6
131131
with:
132132
persist-credentials: false
133133
- name: Install uv
134-
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7
134+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7
135135
with:
136136
enable-cache: true
137137
python-version: "3.10"
@@ -149,11 +149,11 @@ jobs:
149149
matrix:
150150
python: ["3.10", "3.11"]
151151
steps:
152-
- uses: actions/checkout@v5
152+
- uses: actions/checkout@v6
153153
with:
154154
persist-credentials: false
155155
- name: Install uv
156-
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7
156+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7
157157
with:
158158
enable-cache: true
159159
python-version: "${{matrix.python}}"
@@ -170,11 +170,11 @@ jobs:
170170
runs-on: ubuntu-latest
171171
name: Integration Tests
172172
steps:
173-
- uses: actions/checkout@v5
173+
- uses: actions/checkout@v6
174174
with:
175175
persist-credentials: false
176176
- name: Install uv
177-
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7
177+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7
178178
with:
179179
enable-cache: true
180180
python-version: "3.10"
@@ -200,7 +200,7 @@ jobs:
200200
runs-on: ubuntu-latest
201201
name: "Make an sdist"
202202
steps:
203-
- uses: actions/checkout@v5
203+
- uses: actions/checkout@v6
204204
with:
205205
persist-credentials: false
206206
- uses: actions/setup-python@v6
@@ -260,11 +260,11 @@ jobs:
260260
runs-on: ubuntu-latest
261261
name: Test minimum dependencies and Python
262262
steps:
263-
- uses: actions/checkout@v5
263+
- uses: actions/checkout@v6
264264
with:
265265
persist-credentials: false
266266
- name: Install uv
267-
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7
267+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7
268268
with:
269269
python-version: "3.10"
270270
- id: setup-mongodb

.github/workflows/zizmor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
security-events: write
1515
steps:
1616
- name: Checkout repository
17-
uses: actions/checkout@v5
17+
uses: actions/checkout@v6
1818
with:
1919
persist-credentials: false
2020
- name: Run zizmor 🌈
21-
uses: zizmorcore/zizmor-action@1aba86d8e1245be7a9ca003d46fcc85a76e6aa61
21+
uses: zizmorcore/zizmor-action@b0e5c0b2b3785bc67b9b6c743fdbd495cda1b4c4

doc/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ PyMongo 4.16 brings a number of changes including:
1717
- Removed support for Eventlet.
1818
Eventlet is actively being sunset by its maintainers and has compatibility issues with PyMongo's dnspython dependency.
1919
- Use Zstandard support from the standard library for Python 3.14+, and use ``backports.zstd`` for older versions.
20+
- Fixed return type annotation for ``find_one_and_*`` methods on :class:`~pymongo.asynchronous.collection.AsyncCollection`
21+
and :class:`~pymongo.synchronous.collection.Collection` to include ``None``.
22+
23+
Changes in Version 4.15.5 (2025/XX/XX)
24+
--------------------------------------
25+
26+
Version 4.15.5 is a bug fix release.
27+
28+
- Fixed a bug that could cause ``AutoReconnect("connection pool paused")`` errors when cursors fetched more documents from the database after SDAM heartbeat failures.
2029

2130
Changes in Version 4.15.4 (2025/10/21)
2231
--------------------------------------

doc/contributors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,4 @@ The following is a list of people who have contributed to
107107
- Jeffrey A. Clark (aclark4life)
108108
- Steven Silvester (blink1073)
109109
- Noah Stapp (NoahStapp)
110+
- Cal Jacobson (cj81499)

pymongo/asynchronous/collection.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3310,7 +3310,7 @@ async def find_one_and_delete(
33103310
let: Optional[Mapping[str, Any]] = None,
33113311
comment: Optional[Any] = None,
33123312
**kwargs: Any,
3313-
) -> _DocumentType:
3313+
) -> Optional[_DocumentType]:
33143314
"""Finds a single document and deletes it, returning the document.
33153315

33163316
>>> await db.test.count_documents({'x': 1})
@@ -3320,6 +3320,10 @@ async def find_one_and_delete(
33203320
>>> await db.test.count_documents({'x': 1})
33213321
1
33223322

3323+
Returns ``None`` if no document matches the filter.
3324+
3325+
>>> await db.test.find_one_and_delete({'_exists': False})
3326+
33233327
If multiple documents match *filter*, a *sort* can be applied.
33243328

33253329
>>> async for doc in db.test.find({'x': 1}):
@@ -3402,10 +3406,22 @@ async def find_one_and_replace(
34023406
let: Optional[Mapping[str, Any]] = None,
34033407
comment: Optional[Any] = None,
34043408
**kwargs: Any,
3405-
) -> _DocumentType:
3409+
) -> Optional[_DocumentType]:
34063410
"""Finds a single document and replaces it, returning either the
34073411
original or the replaced document.
34083412

3413+
>>> await db.test.find_one({'x': 1})
3414+
{'_id': 0, 'x': 1}
3415+
>>> await db.test.find_one_and_replace({'x': 1}, {'y': 2})
3416+
{'_id': 0, 'x': 1}
3417+
>>> await db.test.find_one({'x': 1})
3418+
>>> await db.test.find_one({'y': 2})
3419+
{'_id': 0, 'y': 2}
3420+
3421+
Returns ``None`` if no document matches the filter.
3422+
3423+
>>> await db.test.find_one_and_replace({'_exists': False}, {'x': 1})
3424+
34093425
The :meth:`find_one_and_replace` method differs from
34103426
:meth:`find_one_and_update` by replacing the document matched by
34113427
*filter*, rather than modifying the existing document.
@@ -3510,13 +3526,17 @@ async def find_one_and_update(
35103526
let: Optional[Mapping[str, Any]] = None,
35113527
comment: Optional[Any] = None,
35123528
**kwargs: Any,
3513-
) -> _DocumentType:
3529+
) -> Optional[_DocumentType]:
35143530
"""Finds a single document and updates it, returning either the
35153531
original or the updated document.
35163532

3533+
>>> await db.test.find_one({'_id': 665})
3534+
{'_id': 665, 'done': False, 'count': 25}
35173535
>>> await db.test.find_one_and_update(
35183536
... {'_id': 665}, {'$inc': {'count': 1}, '$set': {'done': True}})
3519-
{'_id': 665, 'done': False, 'count': 25}}
3537+
{'_id': 665, 'done': False, 'count': 25}
3538+
>>> await db.test.find_one({'_id': 665})
3539+
{'_id': 665, 'done': True, 'count': 26}
35203540

35213541
Returns ``None`` if no document matches the filter.
35223542

pymongo/auth_shared.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ def _build_credentials_tuple(
160160
"127.0.0.1",
161161
"::1",
162162
"*.mongo.com",
163-
"*.mongodbgov.net",
164163
]
165164
allowed_hosts = properties.get("ALLOWED_HOSTS", default_allowed)
166165
if properties.get("ALLOWED_HOSTS", None) is not None and human_callback is None:

0 commit comments

Comments
 (0)