Skip to content

Commit 5a4de6b

Browse files
authored
Merge branch 'master' into PYTHON-5488
2 parents 41e6dbe + de332c5 commit 5a4de6b

22 files changed

+299
-49
lines changed

.evergreen/scripts/install-dependencies.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ if ! command -v just &>/dev/null; then
4848
_TARGET="--target x86_64-pc-windows-msvc"
4949
fi
5050
_BIN_DIR=$PYMONGO_BIN_DIR
51+
mkdir -p ${_BIN_DIR}
5152
echo "Installing just..."
5253
mkdir -p "$_BIN_DIR" 2>/dev/null || true
5354
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- $_TARGET --to "$_BIN_DIR" || {
55+
# Remove just file if it exists (can be created if there was an install error).
56+
rm -f ${_BIN_DIR}/just
5457
_pip_install rust-just just
5558
}
5659
echo "Installing just... done."
@@ -59,6 +62,7 @@ fi
5962
# Ensure uv is installed.
6063
if ! command -v uv &>/dev/null; then
6164
_BIN_DIR=$PYMONGO_BIN_DIR
65+
mkdir -p ${_BIN_DIR}
6266
echo "Installing uv..."
6367
# On most systems we can install directly.
6468
curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="$_BIN_DIR" INSTALLER_NO_MODIFY_PATH=1 sh || {

.evergreen/scripts/kms_tester.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _setup_azure_vm(base_env: dict[str, str]) -> None:
3030
env["AZUREKMS_CMD"] = "tar xf mongo-python-driver.tgz"
3131
run_command(f"{azure_dir}/run-command.sh", env=env)
3232

33-
env["AZUREKMS_CMD"] = "bash .evergreen/just.sh setup-tests kms azure-remote"
33+
env["AZUREKMS_CMD"] = "NO_EXT=1 bash .evergreen/just.sh setup-tests kms azure-remote"
3434
run_command(f"{azure_dir}/run-command.sh", env=env)
3535
LOGGER.info("Setting up Azure VM... done.")
3636

@@ -47,7 +47,7 @@ def _setup_gcp_vm(base_env: dict[str, str]) -> None:
4747
env["GCPKMS_CMD"] = "tar xf mongo-python-driver.tgz"
4848
run_command(f"{gcp_dir}/run-command.sh", env=env)
4949

50-
env["GCPKMS_CMD"] = "bash ./.evergreen/just.sh setup-tests kms gcp-remote"
50+
env["GCPKMS_CMD"] = "NO_EXT=1 bash ./.evergreen/just.sh setup-tests kms gcp-remote"
5151
run_command(f"{gcp_dir}/run-command.sh", env=env)
5252
LOGGER.info("Setting up GCP VM...")
5353

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
diff --git a/test/connection_logging/connection-logging.json b/test/connection_logging/connection-logging.json
2+
index d40cfbb7e..5799e834d 100644
3+
--- a/test/connection_logging/connection-logging.json
4+
+++ b/test/connection_logging/connection-logging.json
5+
@@ -272,7 +272,13 @@
6+
"level": "debug",
7+
"component": "connection",
8+
"data": {
9+
- "message": "Connection pool closed",
10+
+ "message": "Connection closed",
11+
+ "driverConnectionId": {
12+
+ "$$type": [
13+
+ "int",
14+
+ "long"
15+
+ ]
16+
+ },
17+
"serverHost": {
18+
"$$type": "string"
19+
},
20+
@@ -281,20 +287,15 @@
21+
"int",
22+
"long"
23+
]
24+
- }
25+
+ },
26+
+ "reason": "Connection pool was closed"
27+
}
28+
},
29+
{
30+
"level": "debug",
31+
"component": "connection",
32+
"data": {
33+
- "message": "Connection closed",
34+
- "driverConnectionId": {
35+
- "$$type": [
36+
- "int",
37+
- "long"
38+
- ]
39+
- },
40+
+ "message": "Connection pool closed",
41+
"serverHost": {
42+
"$$type": "string"
43+
},
44+
@@ -303,8 +304,7 @@
45+
"int",
46+
"long"
47+
]
48+
- },
49+
- "reason": "Connection pool was closed"
50+
+ }
51+
}
52+
}
53+
]
54+
@@ -446,22 +446,6 @@
55+
}
56+
}
57+
},
58+
- {
59+
- "level": "debug",
60+
- "component": "connection",
61+
- "data": {
62+
- "message": "Connection pool cleared",
63+
- "serverHost": {
64+
- "$$type": "string"
65+
- },
66+
- "serverPort": {
67+
- "$$type": [
68+
- "int",
69+
- "long"
70+
- ]
71+
- }
72+
- }
73+
- },
74+
{
75+
"level": "debug",
76+
"component": "connection",
77+
@@ -514,6 +498,22 @@
78+
]
79+
}
80+
}
81+
+ },
82+
+ {
83+
+ "level": "debug",
84+
+ "component": "connection",
85+
+ "data": {
86+
+ "message": "Connection pool cleared",
87+
+ "serverHost": {
88+
+ "$$type": "string"
89+
+ },
90+
+ "serverPort": {
91+
+ "$$type": [
92+
+ "int",
93+
+ "long"
94+
+ ]
95+
+ }
96+
+ }
97+
}
98+
]
99+
}

.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@76621b61decf072c1cee8dd1ce2d2a82d33c17ed # v3
49+
uses: github/codeql-action/init@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3
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@76621b61decf072c1cee8dd1ce2d2a82d33c17ed # v3
66+
uses: github/codeql-action/analyze@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3
6767
with:
6868
category: "/language:${{matrix.language}}"

.github/workflows/dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
name: Download Wheels
143143
steps:
144144
- name: Download all workflow run artifacts
145-
uses: actions/download-artifact@v5
145+
uses: actions/download-artifact@v4
146146
- name: Flatten directory
147147
working-directory: .
148148
run: |

.github/workflows/release-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
id-token: write
7777
steps:
7878
- name: Download all the dists
79-
uses: actions/download-artifact@v5
79+
uses: actions/download-artifact@v4
8080
with:
8181
name: all-dist-${{ github.run_id }}
8282
path: dist/

.github/workflows/test-python.yml

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,31 @@ jobs:
5050
cppcheck pymongo
5151
5252
build:
53-
# supercharge/mongodb-github-action requires containers so we don't test other platforms
5453
runs-on: ${{ matrix.os }}
5554
strategy:
5655
fail-fast: false
5756
matrix:
57+
# Tests currently only pass on ubuntu on GitHub Actions.
5858
os: [ubuntu-latest]
59-
python-version: ["3.9", "pypy-3.10", "3.13", "3.13t"]
59+
python-version: ["3.9", "pypy-3.10", "3.13t"]
60+
mongodb-version: ["8.0"]
61+
6062
name: CPython ${{ matrix.python-version }}-${{ matrix.os }}
6163
steps:
6264
- uses: actions/checkout@v4
6365
with:
6466
persist-credentials: false
65-
- name: Install just
66-
uses: extractions/setup-just@e33e0265a09d6d736e2ee1e0eb685ef1de4669ff # v3
6767
- name: Install uv
6868
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
6969
with:
7070
enable-cache: true
7171
python-version: ${{ matrix.python-version }}
72-
- name: Install dependencies
73-
run: just install
74-
- name: Start MongoDB
75-
uses: supercharge/mongodb-github-action@90004df786821b6308fb02299e5835d0dae05d0d # 1.12.0
72+
- id: setup-mongodb
73+
uses: mongodb-labs/drivers-evergreen-tools@master
7674
with:
77-
mongodb-version: 6.0
75+
version: "${{ matrix.mongodb-version }}"
7876
- name: Run tests
79-
run: just test
77+
run: uv run --extra test pytest -v
8078

8179
doctest:
8280
runs-on: ubuntu-latest
@@ -92,10 +90,10 @@ jobs:
9290
with:
9391
enable-cache: true
9492
python-version: "3.9"
95-
- name: Start MongoDB
96-
uses: supercharge/mongodb-github-action@90004df786821b6308fb02299e5835d0dae05d0d # 1.12.0
93+
- id: setup-mongodb
94+
uses: mongodb-labs/drivers-evergreen-tools@master
9795
with:
98-
mongodb-version: '8.0.0-rc4'
96+
version: "8.0"
9997
- name: Install dependencies
10098
run: just install
10199
- name: Run tests
@@ -195,7 +193,7 @@ jobs:
195193
timeout-minutes: 20
196194
steps:
197195
- name: Download sdist
198-
uses: actions/download-artifact@v5
196+
uses: actions/download-artifact@v4
199197
- name: Unpack SDist
200198
shell: bash
201199
run: |
@@ -210,8 +208,8 @@ jobs:
210208
cache-dependency-path: 'sdist/test/pyproject.toml'
211209
# Test sdist on lowest supported Python
212210
python-version: '3.9'
213-
- name: Start MongoDB
214-
uses: supercharge/mongodb-github-action@90004df786821b6308fb02299e5835d0dae05d0d # 1.12.0
211+
- id: setup-mongodb
212+
uses: mongodb-labs/drivers-evergreen-tools@master
215213
- name: Run connect test from sdist
216214
shell: bash
217215
run: |
@@ -234,10 +232,10 @@ jobs:
234232
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
235233
with:
236234
python-version: '3.9'
237-
- name: Start MongoDB
238-
uses: supercharge/mongodb-github-action@90004df786821b6308fb02299e5835d0dae05d0d # 1.12.0
235+
- id: setup-mongodb
236+
uses: mongodb-labs/drivers-evergreen-tools@master
239237
with:
240-
mongodb-version: 6.0
238+
version: "8.0"
241239
# Async and our test_dns do not support dnspython 1.X, so we don't run async or dns tests here
242240
- name: Run tests
243241
shell: bash
@@ -260,10 +258,10 @@ jobs:
260258
uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v5
261259
with:
262260
python-version: '3.9'
263-
- name: Start MongoDB
264-
uses: supercharge/mongodb-github-action@90004df786821b6308fb02299e5835d0dae05d0d # 1.12.0
261+
- id: setup-mongodb
262+
uses: mongodb-labs/drivers-evergreen-tools@master
265263
with:
266-
mongodb-version: 6.0
264+
version: "8.0"
267265
# The lifetime kwarg we use in srv resolution was added to the async resolver API in dnspython 2.1.0
268266
- name: Run tests
269267
shell: bash

.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@c17832b972c15fd5f3d5065a7e16ad761a0a10d2
21+
uses: zizmorcore/zizmor-action@383d31df2eb66a2f42db98c9654bdc73231f3e3a

.github/zizmor.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
rules:
2+
unpinned-uses:
3+
config:
4+
policies:
5+
actions/*: ref-pin
6+
mongodb-labs/drivers-github-tools/*: ref-pin
7+
mongodb-labs/drivers-evergreen-tools: ref-pin

pymongo/asynchronous/collection.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,15 @@ def find(self, *args: Any, **kwargs: Any) -> AsyncCursor[_DocumentType]:
17761776
improper type. Returns an instance of
17771777
:class:`~pymongo.asynchronous.cursor.AsyncCursor` corresponding to this query.
17781778
1779+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
1780+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
1781+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
1782+
or use the cursor in a with statement::
1783+
1784+
async with collection.find() as cursor:
1785+
async for doc in cursor:
1786+
print(doc)
1787+
17791788
The :meth:`find` method obeys the :attr:`read_preference` of
17801789
this :class:`AsyncCollection`.
17811790
@@ -2503,6 +2512,15 @@ async def list_indexes(
25032512
...
25042513
SON([('v', 2), ('key', SON([('_id', 1)])), ('name', '_id_')])
25052514
2515+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2516+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2517+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
2518+
or use the cursor in a with statement::
2519+
2520+
async with await collection.list_indexes() as cursor:
2521+
async for index in cursor:
2522+
print(index)
2523+
25062524
:param session: a
25072525
:class:`~pymongo.asynchronous.client_session.AsyncClientSession`.
25082526
:param comment: A user-provided comment to attach to this
@@ -2620,6 +2638,15 @@ async def list_search_indexes(
26202638
) -> AsyncCommandCursor[Mapping[str, Any]]:
26212639
"""Return a cursor over search indexes for the current collection.
26222640
2641+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2642+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2643+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
2644+
or use the cursor in a with statement::
2645+
2646+
async with await collection.list_search_indexes() as cursor:
2647+
async for index in cursor:
2648+
print(index)
2649+
26232650
:param name: If given, the name of the index to search
26242651
for. Only indexes with matching index names will be returned.
26252652
If not given, all search indexes for the current collection
@@ -2922,6 +2949,15 @@ async def aggregate(
29222949
.. note:: The :attr:`~pymongo.asynchronous.collection.AsyncCollection.write_concern` of
29232950
this collection is automatically applied to this operation.
29242951
2952+
Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
2953+
If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
2954+
To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
2955+
or use the cursor in a with statement::
2956+
2957+
async with await collection.aggregate() as cursor:
2958+
async for operation in cursor:
2959+
print(operation)
2960+
29252961
:param pipeline: a list of aggregation pipeline stages
29262962
:param session: a
29272963
:class:`~pymongo.asynchronous.client_session.AsyncClientSession`.

0 commit comments

Comments
 (0)