From 13085ff6791968d573177664abac1ca1ba6929be Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Wed, 18 Mar 2026 13:19:18 -0400 Subject: [PATCH 1/8] PYTHON-5758 Remove unused validation functions (#2733) --- pymongo/common.py | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/pymongo/common.py b/pymongo/common.py index e23adac42..118cca89d 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -233,13 +233,6 @@ def validate_readable(option: str, value: Any) -> Optional[str]: return value -def validate_positive_integer_or_none(option: str, value: Any) -> Optional[int]: - """Validate that 'value' is a positive integer or None.""" - if value is None: - return value - return validate_positive_integer(option, value) - - def validate_non_negative_integer_or_none(option: str, value: Any) -> Optional[int]: """Validate that 'value' is a positive integer or 0 or None.""" if value is None: @@ -261,20 +254,6 @@ def validate_string_or_none(option: str, value: Any) -> Optional[str]: return validate_string(option, value) -def validate_int_or_basestring(option: str, value: Any) -> Union[int, str]: - """Validates that 'value' is an integer or string.""" - if isinstance(value, int): - return value - elif isinstance(value, str): - try: - return int(value) - except ValueError: - return value - raise TypeError( - f"Wrong type for {option}, value must be an integer or a string, not {type(value)}" - ) - - def validate_non_negative_int_or_basestring(option: Any, value: Any) -> Union[int, str]: """Validates that 'value' is an integer or string.""" if isinstance(value, int): @@ -817,16 +796,6 @@ TIMEOUT_OPTIONS: list[str] = [ "waitqueuetimeoutms", ] -_AUTH_OPTIONS = frozenset(["authmechanismproperties"]) - - -def validate_auth_option(option: str, value: Any) -> tuple[str, Any]: - """Validate optional authentication parameters.""" - lower, value = validate(option, value) - if lower not in _AUTH_OPTIONS: - raise ConfigurationError(f"Unknown option: {option}. Must be in {_AUTH_OPTIONS}") - return option, value - def _get_validator( key: str, validators: dict[str, Callable[[Any, Any], Any]], normed_key: Optional[str] = None From ec9d95413c2bc993d8cf0cd7fa7fbd83daf862b8 Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Wed, 18 Mar 2026 17:46:23 -0400 Subject: [PATCH 2/8] PYTHON-5757 Deprecate Python 2 methods in SON (#2732) --- bson/son.py | 16 ++++++++++++++++ doc/changelog.rst | 5 +++++ test/test_son.py | 4 +--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bson/son.py b/bson/son.py index 8fd4f95cd..ccb6bdb27 100644 --- a/bson/son.py +++ b/bson/son.py @@ -22,6 +22,7 @@ from __future__ import annotations import copy import re +import warnings from collections.abc import Mapping as _Mapping from typing import ( Any, @@ -99,13 +100,28 @@ class SON(Dict[_Key, _Value]): yield from self.__keys def has_key(self, key: _Key) -> bool: + warnings.warn( + "SON.has_key() is deprecated, use the in operator instead", + DeprecationWarning, + stacklevel=2, + ) return key in self.__keys def iterkeys(self) -> Iterator[_Key]: + warnings.warn( + "SON.iterkeys() is deprecated, use the keys() method instead", + DeprecationWarning, + stacklevel=2, + ) return self.__iter__() # fourth level uses definitions from lower levels def itervalues(self) -> Iterator[_Value]: + warnings.warn( + "SON.itervalues() is deprecated, use the values() method instead", + DeprecationWarning, + stacklevel=2, + ) for _, v in self.items(): yield v diff --git a/doc/changelog.rst b/doc/changelog.rst index f38709203..23d5b2fc9 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,6 +6,11 @@ Changes in Version 4.17.0 (2026/XX/XX) PyMongo 4.17 brings a number of changes including: +- ``has_key``, ``iterkeys`` and ``itervalues`` in :class:`bson.son.SON` have + been deprecated and will be removed in PyMongo 5.0. These methods were + deprecated in favor of the standard dictionary containment operator ``in`` + and the ``keys()`` and ``values()`` methods, respectively. + - Added the :meth:`~pymongo.asynchronous.client_session.AsyncClientSession.bind` and :meth:`~pymongo.client_session.ClientSession.bind` methods that allow users to bind a session to all database operations within the scope of a context manager instead of having to explicitly pass the session to each individual operation. See for examples and more information. diff --git a/test/test_son.py b/test/test_son.py index 36a683488..3d2069a4c 100644 --- a/test/test_son.py +++ b/test/test_son.py @@ -145,13 +145,11 @@ class TestSON(unittest.TestCase): self.assertEqual(ele * 100, test_son[ele]) def test_contains_has(self): - """has_key and __contains__""" + """Test key membership via 'in' and __contains__.""" test_son = SON([(1, 100), (2, 200), (3, 300)]) self.assertIn(1, test_son) self.assertIn(2, test_son, "in failed") self.assertNotIn(22, test_son, "in succeeded when it shouldn't") - self.assertTrue(test_son.has_key(2), "has_key failed") - self.assertFalse(test_son.has_key(22), "has_key succeeded when it shouldn't") def test_clears(self): """Test clear()""" From c3428789fb8bc2a1be20aa345b8f508d05e79be8 Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Mon, 23 Mar 2026 10:55:50 -0400 Subject: [PATCH 3/8] PYTHON-5766 Add codecov badge to readme (#2737) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c807733e5..c28ef713b 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Python Versions](https://img.shields.io/pypi/pyversions/pymongo)](https://pypi.org/project/pymongo) [![Monthly Downloads](https://static.pepy.tech/badge/pymongo/month)](https://pepy.tech/project/pymongo) [![API Documentation Status](https://readthedocs.org/projects/pymongo/badge/?version=stable)](http://pymongo.readthedocs.io/en/stable/api?badge=stable) +[![codecov](https://codecov.io/gh/mongodb/mongo-python-driver/graph/badge.svg?branch=master)](https://codecov.io/gh/mongodb/mongo-python-driver) ## About From daba50c797abc6ed8cae8d2087002903396c93be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Mar 2026 14:56:12 -0400 Subject: [PATCH 4/8] Bump the actions group across 1 directory with 4 updates (#2736) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dist.yml | 10 +++++----- .github/workflows/release-python.yml | 2 +- .github/workflows/sbom.yml | 2 +- .github/workflows/test-python.yml | 4 ++-- .github/workflows/zizmor.yml | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index 645cb74de..579bcc5f4 100644 --- a/.github/workflows/dist.yml +++ b/.github/workflows/dist.yml @@ -61,7 +61,7 @@ jobs: - name: Set up QEMU if: runner.os == 'Linux' - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 + uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0 with: # setup-qemu-action by default uses `tonistiigi/binfmt:latest` image, # which is out of date. This causes seg faults during build. @@ -92,7 +92,7 @@ jobs: # Free-threading builds: ls wheelhouse/*cp314t*.whl - - uses: actions/upload-artifact@v6 + - uses: actions/upload-artifact@v7 with: name: wheel-${{ matrix.buildplat[1] }} path: ./wheelhouse/*.whl @@ -125,7 +125,7 @@ jobs: cd .. python -c "from pymongo import has_c; assert has_c()" - - uses: actions/upload-artifact@v6 + - uses: actions/upload-artifact@v7 with: name: "sdist" path: ./dist/*.tar.gz @@ -136,13 +136,13 @@ jobs: name: Download Wheels steps: - name: Download all workflow run artifacts - uses: actions/download-artifact@v7 + uses: actions/download-artifact@v8 - name: Flatten directory working-directory: . run: | find . -mindepth 2 -type f -exec mv {} . \; find . -type d -empty -delete - - uses: actions/upload-artifact@v6 + - uses: actions/upload-artifact@v7 with: name: all-dist-${{ github.run_id }} path: "./*" diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml index e3dd1edb1..438730322 100644 --- a/.github/workflows/release-python.yml +++ b/.github/workflows/release-python.yml @@ -75,7 +75,7 @@ jobs: id-token: write steps: - name: Download all the dists - uses: actions/download-artifact@v7 + uses: actions/download-artifact@v8 with: name: all-dist-${{ github.run_id }} path: dist/ diff --git a/.github/workflows/sbom.yml b/.github/workflows/sbom.yml index 69a07c8be..ce7308cf1 100644 --- a/.github/workflows/sbom.yml +++ b/.github/workflows/sbom.yml @@ -67,7 +67,7 @@ jobs: run: rm -rf .venv .venv-sbom sbom-requirements.txt - name: Upload SBOM artifact - uses: actions/upload-artifact@v6 + uses: actions/upload-artifact@v7 with: name: sbom path: sbom.json diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index e8fb9b918..7c7793ed2 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -245,7 +245,7 @@ jobs: run: | pip install build python -m build --sdist - - uses: actions/upload-artifact@v6 + - uses: actions/upload-artifact@v7 with: name: "sdist" path: dist/*.tar.gz @@ -257,7 +257,7 @@ jobs: timeout-minutes: 20 steps: - name: Download sdist - uses: actions/download-artifact@v7 + uses: actions/download-artifact@v8 with: path: sdist/ - name: Unpack SDist diff --git a/.github/workflows/zizmor.yml b/.github/workflows/zizmor.yml index c64a9e32e..6a642977b 100644 --- a/.github/workflows/zizmor.yml +++ b/.github/workflows/zizmor.yml @@ -18,4 +18,4 @@ jobs: with: persist-credentials: false - name: Run zizmor 🌈 - uses: zizmorcore/zizmor-action@0dce2577a4760a2749d8cfb7a84b7d5585ebcb7d # v0.5.0 + uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2 From ce416a094450c3702670a6793781ae9fa9eeeae5 Mon Sep 17 00:00:00 2001 From: "mongodb-drivers-pr-bot[bot]" <147046816+mongodb-drivers-pr-bot[bot]@users.noreply.github.com> Date: Tue, 31 Mar 2026 11:41:46 -0700 Subject: [PATCH 5/8] [Spec Resync] 03-30-2026 (#2741) Co-authored-by: Cloud User Co-authored-by: Iris Ho --- .evergreen/spec-patch/PYTHON-5668.patch | 1578 +++++++++++++++++++++++ .evergreen/spec-patch/PYTHON-5759.patch | 460 +++++++ 2 files changed, 2038 insertions(+) create mode 100644 .evergreen/spec-patch/PYTHON-5668.patch create mode 100644 .evergreen/spec-patch/PYTHON-5759.patch diff --git a/.evergreen/spec-patch/PYTHON-5668.patch b/.evergreen/spec-patch/PYTHON-5668.patch new file mode 100644 index 000000000..d48b18fe6 --- /dev/null +++ b/.evergreen/spec-patch/PYTHON-5668.patch @@ -0,0 +1,1578 @@ +diff --git a/test/transactions/unified/backpressure-retryable-abort.json b/test/transactions/unified/backpressure-retryable-abort.json +new file mode 100644 +index 00000000..53fc9c6f +--- /dev/null ++++ b/test/transactions/unified/backpressure-retryable-abort.json +@@ -0,0 +1,357 @@ ++{ ++ "description": "backpressure-retryable-abort", ++ "schemaVersion": "1.3", ++ "runOnRequirements": [ ++ { ++ "minServerVersion": "4.4", ++ "topologies": [ ++ "replicaset", ++ "sharded", ++ "load-balanced" ++ ] ++ } ++ ], ++ "createEntities": [ ++ { ++ "client": { ++ "id": "client0", ++ "useMultipleMongoses": false, ++ "observeEvents": [ ++ "commandStartedEvent" ++ ] ++ } ++ }, ++ { ++ "database": { ++ "id": "database0", ++ "client": "client0", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "collection": { ++ "id": "collection0", ++ "database": "database0", ++ "collectionName": "test" ++ } ++ }, ++ { ++ "session": { ++ "id": "session0", ++ "client": "client0" ++ } ++ } ++ ], ++ "initialData": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [] ++ } ++ ], ++ "tests": [ ++ { ++ "description": "abortTransaction retries if backpressure labels are added", ++ "operations": [ ++ { ++ "object": "testRunner", ++ "name": "failPoint", ++ "arguments": { ++ "client": "client0", ++ "failPoint": { ++ "configureFailPoint": "failCommand", ++ "mode": { ++ "times": 2 ++ }, ++ "data": { ++ "failCommands": [ ++ "abortTransaction" ++ ], ++ "errorLabels": [ ++ "RetryableError", ++ "SystemOverloadedError" ++ ], ++ "errorCode": 112 ++ } ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "startTransaction" ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 1 ++ } ++ }, ++ "expectResult": { ++ "$$unsetOrMatches": { ++ "insertedId": { ++ "$$unsetOrMatches": 1 ++ } ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "abortTransaction" ++ } ++ ], ++ "expectEvents": [ ++ { ++ "client": "client0", ++ "events": [ ++ { ++ "commandStartedEvent": { ++ "command": { ++ "insert": "test", ++ "documents": [ ++ { ++ "_id": 1 ++ } ++ ], ++ "ordered": true, ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": true, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "abortTransaction": 1, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "abortTransaction", ++ "databaseName": "admin" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "abortTransaction": 1, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "abortTransaction", ++ "databaseName": "admin" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "abortTransaction": 1, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "abortTransaction", ++ "databaseName": "admin" ++ } ++ } ++ ] ++ } ++ ], ++ "outcome": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [] ++ } ++ ] ++ }, ++ { ++ "description": "abortTransaction is retried maxAttempts=5 times if backpressure labels are added", ++ "operations": [ ++ { ++ "object": "testRunner", ++ "name": "failPoint", ++ "arguments": { ++ "client": "client0", ++ "failPoint": { ++ "configureFailPoint": "failCommand", ++ "mode": "alwaysOn", ++ "data": { ++ "failCommands": [ ++ "abortTransaction" ++ ], ++ "errorLabels": [ ++ "RetryableError", ++ "SystemOverloadedError" ++ ], ++ "errorCode": 112 ++ } ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "startTransaction" ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 1 ++ } ++ }, ++ "expectResult": { ++ "$$unsetOrMatches": { ++ "insertedId": { ++ "$$unsetOrMatches": 1 ++ } ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "abortTransaction" ++ } ++ ], ++ "expectEvents": [ ++ { ++ "client": "client0", ++ "events": [ ++ { ++ "commandStartedEvent": { ++ "command": { ++ "insert": "test", ++ "documents": [ ++ { ++ "_id": 1 ++ } ++ ], ++ "ordered": true, ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": true, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "abortTransaction": 1, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "abortTransaction", ++ "databaseName": "admin" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "abortTransaction" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "abortTransaction" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "abortTransaction" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "abortTransaction" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "abortTransaction" ++ } ++ } ++ ] ++ } ++ ], ++ "outcome": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [] ++ } ++ ] ++ } ++ ] ++} +diff --git a/test/transactions/unified/backpressure-retryable-commit.json b/test/transactions/unified/backpressure-retryable-commit.json +new file mode 100644 +index 00000000..ae873561 +--- /dev/null ++++ b/test/transactions/unified/backpressure-retryable-commit.json +@@ -0,0 +1,374 @@ ++{ ++ "description": "backpressure-retryable-commit", ++ "schemaVersion": "1.4", ++ "runOnRequirements": [ ++ { ++ "minServerVersion": "4.4", ++ "topologies": [ ++ "sharded", ++ "replicaset", ++ "load-balanced" ++ ] ++ } ++ ], ++ "createEntities": [ ++ { ++ "client": { ++ "id": "client0", ++ "useMultipleMongoses": false, ++ "observeEvents": [ ++ "commandStartedEvent" ++ ] ++ } ++ }, ++ { ++ "database": { ++ "id": "database0", ++ "client": "client0", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "collection": { ++ "id": "collection0", ++ "database": "database0", ++ "collectionName": "test" ++ } ++ }, ++ { ++ "session": { ++ "id": "session0", ++ "client": "client0" ++ } ++ } ++ ], ++ "initialData": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [] ++ } ++ ], ++ "tests": [ ++ { ++ "description": "commitTransaction retries if backpressure labels are added", ++ "runOnRequirements": [ ++ { ++ "serverless": "forbid" ++ } ++ ], ++ "operations": [ ++ { ++ "object": "testRunner", ++ "name": "failPoint", ++ "arguments": { ++ "client": "client0", ++ "failPoint": { ++ "configureFailPoint": "failCommand", ++ "mode": { ++ "times": 2 ++ }, ++ "data": { ++ "failCommands": [ ++ "commitTransaction" ++ ], ++ "errorLabels": [ ++ "RetryableError", ++ "SystemOverloadedError" ++ ], ++ "errorCode": 112 ++ } ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "startTransaction" ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 1 ++ } ++ }, ++ "expectResult": { ++ "$$unsetOrMatches": { ++ "insertedId": { ++ "$$unsetOrMatches": 1 ++ } ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "commitTransaction" ++ } ++ ], ++ "expectEvents": [ ++ { ++ "client": "client0", ++ "events": [ ++ { ++ "commandStartedEvent": { ++ "command": { ++ "insert": "test", ++ "documents": [ ++ { ++ "_id": 1 ++ } ++ ], ++ "ordered": true, ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": true, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "commitTransaction": 1, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "commitTransaction", ++ "databaseName": "admin" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "commitTransaction": 1, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "commitTransaction", ++ "databaseName": "admin" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "commitTransaction": 1, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "commitTransaction", ++ "databaseName": "admin" ++ } ++ } ++ ] ++ } ++ ], ++ "outcome": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [ ++ { ++ "_id": 1 ++ } ++ ] ++ } ++ ] ++ }, ++ { ++ "description": "commitTransaction is retried maxAttempts=5 times if backpressure labels are added", ++ "runOnRequirements": [ ++ { ++ "serverless": "forbid" ++ } ++ ], ++ "operations": [ ++ { ++ "object": "testRunner", ++ "name": "failPoint", ++ "arguments": { ++ "client": "client0", ++ "failPoint": { ++ "configureFailPoint": "failCommand", ++ "mode": "alwaysOn", ++ "data": { ++ "failCommands": [ ++ "commitTransaction" ++ ], ++ "errorLabels": [ ++ "RetryableError", ++ "SystemOverloadedError" ++ ], ++ "errorCode": 112 ++ } ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "startTransaction" ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 1 ++ } ++ }, ++ "expectResult": { ++ "$$unsetOrMatches": { ++ "insertedId": { ++ "$$unsetOrMatches": 1 ++ } ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "commitTransaction", ++ "expectError": { ++ "isError": true ++ } ++ } ++ ], ++ "expectEvents": [ ++ { ++ "client": "client0", ++ "events": [ ++ { ++ "commandStartedEvent": { ++ "command": { ++ "insert": "test", ++ "documents": [ ++ { ++ "_id": 1 ++ } ++ ], ++ "ordered": true, ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": true, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "commitTransaction": 1, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "commitTransaction", ++ "databaseName": "admin" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "commitTransaction" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "commitTransaction" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "commitTransaction" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "commitTransaction" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "commitTransaction" ++ } ++ } ++ ] ++ } ++ ], ++ "outcome": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [] ++ } ++ ] ++ } ++ ] ++} +diff --git a/test/transactions/unified/backpressure-retryable-reads.json b/test/transactions/unified/backpressure-retryable-reads.json +new file mode 100644 +index 00000000..73176283 +--- /dev/null ++++ b/test/transactions/unified/backpressure-retryable-reads.json +@@ -0,0 +1,328 @@ ++{ ++ "description": "backpressure-retryable-reads", ++ "schemaVersion": "1.3", ++ "runOnRequirements": [ ++ { ++ "minServerVersion": "4.4", ++ "topologies": [ ++ "replicaset", ++ "sharded", ++ "load-balanced" ++ ] ++ } ++ ], ++ "createEntities": [ ++ { ++ "client": { ++ "id": "client0", ++ "useMultipleMongoses": false, ++ "observeEvents": [ ++ "commandStartedEvent" ++ ] ++ } ++ }, ++ { ++ "database": { ++ "id": "database0", ++ "client": "client0", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "collection": { ++ "id": "collection0", ++ "database": "database0", ++ "collectionName": "test" ++ } ++ }, ++ { ++ "session": { ++ "id": "session0", ++ "client": "client0" ++ } ++ } ++ ], ++ "initialData": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [] ++ } ++ ], ++ "tests": [ ++ { ++ "description": "reads are retried if backpressure labels are added", ++ "operations": [ ++ { ++ "object": "session0", ++ "name": "startTransaction" ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 1 ++ } ++ }, ++ "expectResult": { ++ "$$unsetOrMatches": { ++ "insertedId": { ++ "$$unsetOrMatches": 1 ++ } ++ } ++ } ++ }, ++ { ++ "object": "testRunner", ++ "name": "failPoint", ++ "arguments": { ++ "client": "client0", ++ "failPoint": { ++ "configureFailPoint": "failCommand", ++ "mode": { ++ "times": 1 ++ }, ++ "data": { ++ "failCommands": [ ++ "find" ++ ], ++ "errorLabels": [ ++ "RetryableError", ++ "SystemOverloadedError" ++ ], ++ "errorCode": 112 ++ } ++ } ++ } ++ }, ++ { ++ "object": "collection0", ++ "name": "find", ++ "arguments": { ++ "filter": {}, ++ "session": "session0" ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "commitTransaction" ++ } ++ ], ++ "expectEvents": [ ++ { ++ "client": "client0", ++ "events": [ ++ { ++ "commandStartedEvent": { ++ "command": { ++ "insert": "test", ++ "documents": [ ++ { ++ "_id": 1 ++ } ++ ], ++ "ordered": true, ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": true, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "find": "test", ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "find", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "find": "test", ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "find", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "abortTransaction": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "commitTransaction", ++ "databaseName": "admin" ++ } ++ } ++ ] ++ } ++ ] ++ }, ++ { ++ "description": "reads are retried maxAttempts=5 times if backpressure labels are added", ++ "operations": [ ++ { ++ "object": "session0", ++ "name": "startTransaction" ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 1 ++ } ++ }, ++ "expectResult": { ++ "$$unsetOrMatches": { ++ "insertedId": { ++ "$$unsetOrMatches": 1 ++ } ++ } ++ } ++ }, ++ { ++ "object": "testRunner", ++ "name": "failPoint", ++ "arguments": { ++ "client": "client0", ++ "failPoint": { ++ "configureFailPoint": "failCommand", ++ "mode": "alwaysOn", ++ "data": { ++ "failCommands": [ ++ "find" ++ ], ++ "errorLabels": [ ++ "RetryableError", ++ "SystemOverloadedError" ++ ], ++ "errorCode": 112 ++ } ++ } ++ } ++ }, ++ { ++ "object": "collection0", ++ "name": "find", ++ "arguments": { ++ "filter": {}, ++ "session": "session0" ++ }, ++ "expectError": { ++ "isError": true ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "abortTransaction" ++ } ++ ], ++ "expectEvents": [ ++ { ++ "client": "client0", ++ "events": [ ++ { ++ "commandStartedEvent": { ++ "commandName": "insert" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "find" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "find" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "find" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "find" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "find" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "find" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "abortTransaction" ++ } ++ } ++ ] ++ } ++ ] ++ } ++ ] ++} +diff --git a/test/transactions/unified/backpressure-retryable-writes.json b/test/transactions/unified/backpressure-retryable-writes.json +new file mode 100644 +index 00000000..eea0e6b5 +--- /dev/null ++++ b/test/transactions/unified/backpressure-retryable-writes.json +@@ -0,0 +1,454 @@ ++{ ++ "description": "backpressure-retryable-writes", ++ "schemaVersion": "1.3", ++ "runOnRequirements": [ ++ { ++ "minServerVersion": "4.4", ++ "topologies": [ ++ "replicaset", ++ "sharded", ++ "load-balanced" ++ ] ++ } ++ ], ++ "createEntities": [ ++ { ++ "client": { ++ "id": "client0", ++ "useMultipleMongoses": false, ++ "observeEvents": [ ++ "commandStartedEvent" ++ ] ++ } ++ }, ++ { ++ "database": { ++ "id": "database0", ++ "client": "client0", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "collection": { ++ "id": "collection0", ++ "database": "database0", ++ "collectionName": "test" ++ } ++ }, ++ { ++ "session": { ++ "id": "session0", ++ "client": "client0" ++ } ++ } ++ ], ++ "initialData": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [] ++ } ++ ], ++ "tests": [ ++ { ++ "description": "writes are retried if backpressure labels are added", ++ "operations": [ ++ { ++ "object": "session0", ++ "name": "startTransaction" ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 1 ++ } ++ }, ++ "expectResult": { ++ "$$unsetOrMatches": { ++ "insertedId": { ++ "$$unsetOrMatches": 1 ++ } ++ } ++ } ++ }, ++ { ++ "object": "testRunner", ++ "name": "failPoint", ++ "arguments": { ++ "client": "client0", ++ "failPoint": { ++ "configureFailPoint": "failCommand", ++ "mode": { ++ "times": 1 ++ }, ++ "data": { ++ "failCommands": [ ++ "insert" ++ ], ++ "errorLabels": [ ++ "RetryableError", ++ "SystemOverloadedError" ++ ], ++ "errorCode": 112 ++ } ++ } ++ } ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 2 ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "commitTransaction" ++ } ++ ], ++ "expectEvents": [ ++ { ++ "client": "client0", ++ "events": [ ++ { ++ "commandStartedEvent": { ++ "command": { ++ "insert": "test", ++ "documents": [ ++ { ++ "_id": 1 ++ } ++ ], ++ "ordered": true, ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": true, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "insert": "test", ++ "documents": [ ++ { ++ "_id": 2 ++ } ++ ], ++ "ordered": true, ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "insert": "test", ++ "documents": [ ++ { ++ "_id": 2 ++ } ++ ], ++ "ordered": true, ++ "readConcern": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "abortTransaction": { ++ "$$exists": false ++ }, ++ "lsid": { ++ "$$sessionLsid": "session0" ++ }, ++ "txnNumber": { ++ "$numberLong": "1" ++ }, ++ "startTransaction": { ++ "$$exists": false ++ }, ++ "autocommit": false, ++ "writeConcern": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "commitTransaction", ++ "databaseName": "admin" ++ } ++ } ++ ] ++ } ++ ], ++ "outcome": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [ ++ { ++ "_id": 1 ++ }, ++ { ++ "_id": 2 ++ } ++ ] ++ } ++ ] ++ }, ++ { ++ "description": "writes are retried maxAttempts=5 times if backpressure labels are added", ++ "operations": [ ++ { ++ "object": "session0", ++ "name": "startTransaction" ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 1 ++ } ++ }, ++ "expectResult": { ++ "$$unsetOrMatches": { ++ "insertedId": { ++ "$$unsetOrMatches": 1 ++ } ++ } ++ } ++ }, ++ { ++ "object": "testRunner", ++ "name": "failPoint", ++ "arguments": { ++ "client": "client0", ++ "failPoint": { ++ "configureFailPoint": "failCommand", ++ "mode": "alwaysOn", ++ "data": { ++ "failCommands": [ ++ "insert" ++ ], ++ "errorLabels": [ ++ "RetryableError", ++ "SystemOverloadedError" ++ ], ++ "errorCode": 112 ++ } ++ } ++ } ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 2 ++ } ++ }, ++ "expectError": { ++ "isError": true ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "abortTransaction" ++ } ++ ], ++ "expectEvents": [ ++ { ++ "client": "client0", ++ "events": [ ++ { ++ "commandStartedEvent": { ++ "commandName": "insert" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "insert" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "insert" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "insert" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "insert" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "insert" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "insert" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "commandName": "abortTransaction" ++ } ++ } ++ ] ++ } ++ ], ++ "outcome": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [] ++ } ++ ] ++ }, ++ { ++ "description": "retry succeeds if backpressure labels are added to the first operation in a transaction", ++ "operations": [ ++ { ++ "object": "session0", ++ "name": "startTransaction" ++ }, ++ { ++ "object": "testRunner", ++ "name": "failPoint", ++ "arguments": { ++ "client": "client0", ++ "failPoint": { ++ "configureFailPoint": "failCommand", ++ "mode": { ++ "times": 1 ++ }, ++ "data": { ++ "failCommands": [ ++ "insert" ++ ], ++ "errorLabels": [ ++ "RetryableError", ++ "SystemOverloadedError" ++ ], ++ "errorCode": 112 ++ } ++ } ++ } ++ }, ++ { ++ "object": "collection0", ++ "name": "insertOne", ++ "arguments": { ++ "session": "session0", ++ "document": { ++ "_id": 2 ++ } ++ } ++ }, ++ { ++ "object": "session0", ++ "name": "abortTransaction" ++ } ++ ], ++ "expectEvents": [ ++ { ++ "client": "client0", ++ "events": [ ++ { ++ "commandStartedEvent": { ++ "command": { ++ "startTransaction": true ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "startTransaction": true ++ }, ++ "commandName": "insert", ++ "databaseName": "transaction-tests" ++ } ++ }, ++ { ++ "commandStartedEvent": { ++ "command": { ++ "startTransaction": { ++ "$$exists": false ++ } ++ }, ++ "commandName": "abortTransaction", ++ "databaseName": "admin" ++ } ++ } ++ ] ++ } ++ ], ++ "outcome": [ ++ { ++ "collectionName": "test", ++ "databaseName": "transaction-tests", ++ "documents": [] ++ } ++ ] ++ } ++ ] ++} +diff --git b/test/uri_options/client-backpressure-options.json a/test/uri_options/client-backpressure-options.json +new file mode 100644 +index 00000000..3fcf2c86 +--- /dev/null ++++ a/test/uri_options/client-backpressure-options.json +@@ -0,0 +1,35 @@ ++{ ++ "tests": [ ++ { ++ "description": "adaptiveRetries=true is parsed correctly", ++ "uri": "mongodb://example.com/?adaptiveRetries=true", ++ "valid": true, ++ "warning": false, ++ "hosts": null, ++ "auth": null, ++ "options": { ++ "adaptiveRetries": true ++ } ++ }, ++ { ++ "description": "adaptiveRetries=false is parsed correctly", ++ "uri": "mongodb://example.com/?adaptiveRetries=false", ++ "valid": true, ++ "warning": false, ++ "hosts": null, ++ "auth": null, ++ "options": { ++ "adaptiveRetries": false ++ } ++ }, ++ { ++ "description": "adaptiveRetries with invalid value causes a warning", ++ "uri": "mongodb://example.com/?adaptiveRetries=invalid", ++ "valid": true, ++ "warning": true, ++ "hosts": null, ++ "auth": null, ++ "options": null ++ } ++ ] ++} diff --git a/.evergreen/spec-patch/PYTHON-5759.patch b/.evergreen/spec-patch/PYTHON-5759.patch new file mode 100644 index 000000000..3b19ed065 --- /dev/null +++ b/.evergreen/spec-patch/PYTHON-5759.patch @@ -0,0 +1,460 @@ +diff --git a/test/client-side-encryption/spec/unified/accessToken-azure.json b/test/client-side-encryption/spec/unified/accessToken-azure.json +new file mode 100644 +index 00000000..510d8795 +--- /dev/null ++++ b/test/client-side-encryption/spec/unified/accessToken-azure.json +@@ -0,0 +1,186 @@ ++{ ++ "description": "accessToken-azure", ++ "schemaVersion": "1.28", ++ "runOnRequirements": [ ++ { ++ "minServerVersion": "4.1.10", ++ "csfle": { ++ "minLibmongocryptVersion": "1.6.0" ++ } ++ } ++ ], ++ "createEntities": [ ++ { ++ "client": { ++ "id": "client", ++ "autoEncryptOpts": { ++ "keyVaultNamespace": "keyvault.datakeys", ++ "kmsProviders": { ++ "azure": { ++ "accessToken": { ++ "$$placeholder": 1 ++ } ++ } ++ } ++ } ++ } ++ }, ++ { ++ "database": { ++ "id": "db", ++ "client": "client", ++ "databaseName": "db" ++ } ++ }, ++ { ++ "collection": { ++ "id": "coll", ++ "database": "db", ++ "collectionName": "coll" ++ } ++ }, ++ { ++ "clientEncryption": { ++ "id": "clientEncryption", ++ "clientEncryptionOpts": { ++ "keyVaultClient": "client", ++ "keyVaultNamespace": "keyvault.datakeys", ++ "kmsProviders": { ++ "azure": { ++ "accessToken": { ++ "$$placeholder": 1 ++ } ++ } ++ } ++ } ++ } ++ } ++ ], ++ "initialData": [ ++ { ++ "databaseName": "db", ++ "collectionName": "coll", ++ "documents": [], ++ "createOptions": { ++ "validator": { ++ "$jsonSchema": { ++ "properties": { ++ "secret": { ++ "encrypt": { ++ "keyId": [ ++ { ++ "$binary": { ++ "base64": "AZURE+AAAAAAAAAAAAAAAA==", ++ "subType": "04" ++ } ++ } ++ ], ++ "bsonType": "string", ++ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" ++ } ++ } ++ }, ++ "bsonType": "object" ++ } ++ } ++ } ++ }, ++ { ++ "databaseName": "keyvault", ++ "collectionName": "datakeys", ++ "documents": [ ++ { ++ "_id": { ++ "$binary": { ++ "base64": "AZURE+AAAAAAAAAAAAAAAA==", ++ "subType": "04" ++ } ++ }, ++ "keyAltNames": [ ++ "my-key" ++ ], ++ "keyMaterial": { ++ "$binary": { ++ "base64": "n+HWZ0ZSVOYA3cvQgP7inN4JSXfOH85IngmeQxRpQHjCCcqT3IFqEWNlrsVHiz3AELimHhX4HKqOLWMUeSIT6emUDDoQX9BAv8DR1+E1w4nGs/NyEneac78EYFkK3JysrFDOgl2ypCCTKAypkn9CkAx1if4cfgQE93LW4kczcyHdGiH36CIxrCDGv1UzAvERN5Qa47DVwsM6a+hWsF2AAAJVnF0wYLLJU07TuRHdMrrphPWXZsFgyV+lRqJ7DDpReKNO8nMPLV/mHqHBHGPGQiRdb9NoJo8CvokGz4+KE8oLwzKf6V24dtwZmRkrsDV4iOhvROAzz+Euo1ypSkL3mw==", ++ "subType": "00" ++ } ++ }, ++ "creationDate": { ++ "$date": { ++ "$numberLong": "1552949630483" ++ } ++ }, ++ "updateDate": { ++ "$date": { ++ "$numberLong": "1552949630483" ++ } ++ }, ++ "status": { ++ "$numberInt": "0" ++ }, ++ "masterKey": { ++ "provider": "azure", ++ "keyVaultEndpoint": "key-vault-csfle.vault.azure.net", ++ "keyName": "key-name-csfle" ++ } ++ } ++ ] ++ } ++ ], ++ "tests": [ ++ { ++ "description": "Auto encrypt using access token Azure credentials", ++ "operations": [ ++ { ++ "name": "insertOne", ++ "arguments": { ++ "document": { ++ "_id": 1, ++ "secret": "string0" ++ } ++ }, ++ "object": "coll" ++ } ++ ], ++ "outcome": [ ++ { ++ "documents": [ ++ { ++ "_id": 1, ++ "secret": { ++ "$binary": { ++ "base64": "AQGVERPgAAAAAAAAAAAAAAAC5DbBSwPwfSlBrDtRuglvNvCXD1KzDuCKY2P+4bRFtHDjpTOE2XuytPAUaAbXf1orsPq59PVZmsbTZbt2CB8qaQ==", ++ "subType": "06" ++ } ++ } ++ } ++ ], ++ "collectionName": "coll", ++ "databaseName": "db" ++ } ++ ] ++ }, ++ { ++ "description": "Explicit encrypt using access token Azure credentials", ++ "operations": [ ++ { ++ "name": "encrypt", ++ "object": "clientEncryption", ++ "arguments": { ++ "value": "string0", ++ "opts": { ++ "keyAltName": "my-key", ++ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" ++ } ++ }, ++ "expectResult": { ++ "$binary": { ++ "base64": "AQGVERPgAAAAAAAAAAAAAAAC5DbBSwPwfSlBrDtRuglvNvCXD1KzDuCKY2P+4bRFtHDjpTOE2XuytPAUaAbXf1orsPq59PVZmsbTZbt2CB8qaQ==", ++ "subType": "06" ++ } ++ } ++ } ++ ] ++ } ++ ] ++} +diff --git a/test/client-side-encryption/spec/unified/accessToken-gcp.json b/test/client-side-encryption/spec/unified/accessToken-gcp.json +new file mode 100644 +index 00000000..f5cf8914 +--- /dev/null ++++ b/test/client-side-encryption/spec/unified/accessToken-gcp.json +@@ -0,0 +1,188 @@ ++{ ++ "description": "accessToken-gcp", ++ "schemaVersion": "1.28", ++ "runOnRequirements": [ ++ { ++ "minServerVersion": "4.1.10", ++ "csfle": { ++ "minLibmongocryptVersion": "1.6.0" ++ } ++ } ++ ], ++ "createEntities": [ ++ { ++ "client": { ++ "id": "client", ++ "autoEncryptOpts": { ++ "keyVaultNamespace": "keyvault.datakeys", ++ "kmsProviders": { ++ "gcp": { ++ "accessToken": { ++ "$$placeholder": 1 ++ } ++ } ++ } ++ } ++ } ++ }, ++ { ++ "database": { ++ "id": "db", ++ "client": "client", ++ "databaseName": "db" ++ } ++ }, ++ { ++ "collection": { ++ "id": "coll", ++ "database": "db", ++ "collectionName": "coll" ++ } ++ }, ++ { ++ "clientEncryption": { ++ "id": "clientEncryption", ++ "clientEncryptionOpts": { ++ "keyVaultClient": "client", ++ "keyVaultNamespace": "keyvault.datakeys", ++ "kmsProviders": { ++ "gcp": { ++ "accessToken": { ++ "$$placeholder": 1 ++ } ++ } ++ } ++ } ++ } ++ } ++ ], ++ "initialData": [ ++ { ++ "databaseName": "db", ++ "collectionName": "coll", ++ "documents": [], ++ "createOptions": { ++ "validator": { ++ "$jsonSchema": { ++ "properties": { ++ "secret": { ++ "encrypt": { ++ "keyId": [ ++ { ++ "$binary": { ++ "base64": "GCP+AAAAAAAAAAAAAAAAAA==", ++ "subType": "04" ++ } ++ } ++ ], ++ "bsonType": "string", ++ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" ++ } ++ } ++ }, ++ "bsonType": "object" ++ } ++ } ++ } ++ }, ++ { ++ "databaseName": "keyvault", ++ "collectionName": "datakeys", ++ "documents": [ ++ { ++ "_id": { ++ "$binary": { ++ "base64": "GCP+AAAAAAAAAAAAAAAAAA==", ++ "subType": "04" ++ } ++ }, ++ "keyAltNames": [ ++ "my-key" ++ ], ++ "keyMaterial": { ++ "$binary": { ++ "base64": "CiQAIgLj0WyktnB4dfYHo5SLZ41K4ASQrjJUaSzl5vvVH0G12G0SiQEAjlV8XPlbnHDEDFbdTO4QIe8ER2/172U1ouLazG0ysDtFFIlSvWX5ZnZUrRMmp/R2aJkzLXEt/zf8Mn4Lfm+itnjgo5R9K4pmPNvvPKNZX5C16lrPT+aA+rd+zXFSmlMg3i5jnxvTdLHhg3G7Q/Uv1ZIJskKt95bzLoe0tUVzRWMYXLIEcohnQg==", ++ "subType": "00" ++ } ++ }, ++ "creationDate": { ++ "$date": { ++ "$numberLong": "1552949630483" ++ } ++ }, ++ "updateDate": { ++ "$date": { ++ "$numberLong": "1552949630483" ++ } ++ }, ++ "status": { ++ "$numberInt": "0" ++ }, ++ "masterKey": { ++ "provider": "gcp", ++ "projectId": "devprod-drivers", ++ "location": "global", ++ "keyRing": "key-ring-csfle", ++ "keyName": "key-name-csfle" ++ } ++ } ++ ] ++ } ++ ], ++ "tests": [ ++ { ++ "description": "Auto encrypt using access token GCP credentials", ++ "operations": [ ++ { ++ "name": "insertOne", ++ "arguments": { ++ "document": { ++ "_id": 1, ++ "secret": "string0" ++ } ++ }, ++ "object": "coll" ++ } ++ ], ++ "outcome": [ ++ { ++ "documents": [ ++ { ++ "_id": 1, ++ "secret": { ++ "$binary": { ++ "base64": "ARgj/gAAAAAAAAAAAAAAAAACwFd+Y5Ojw45GUXNvbcIpN9YkRdoHDHkR4kssdn0tIMKlDQOLFkWFY9X07IRlXsxPD8DcTiKnl6XINK28vhcGlg==", ++ "subType": "06" ++ } ++ } ++ } ++ ], ++ "collectionName": "coll", ++ "databaseName": "db" ++ } ++ ] ++ }, ++ { ++ "description": "Explicit encrypt using access token GCP credentials", ++ "operations": [ ++ { ++ "name": "encrypt", ++ "object": "clientEncryption", ++ "arguments": { ++ "value": "string0", ++ "opts": { ++ "keyAltName": "my-key", ++ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" ++ } ++ }, ++ "expectResult": { ++ "$binary": { ++ "base64": "ARgj/gAAAAAAAAAAAAAAAAACwFd+Y5Ojw45GUXNvbcIpN9YkRdoHDHkR4kssdn0tIMKlDQOLFkWFY9X07IRlXsxPD8DcTiKnl6XINK28vhcGlg==", ++ "subType": "06" ++ } ++ } ++ } ++ ] ++ } ++ ] ++} +diff --git a/test/unified-test-format/invalid/clientEncryptionOpts-kmsProviders-azure-accessToken-type.json b/test/unified-test-format/invalid/clientEncryptionOpts-kmsProviders-azure-accessToken-type.json +new file mode 100644 +index 00000000..8fe5c150 +--- /dev/null ++++ b/test/unified-test-format/invalid/clientEncryptionOpts-kmsProviders-azure-accessToken-type.json +@@ -0,0 +1,31 @@ ++{ ++ "description": "clientEncryptionOpts-kmsProviders-azure-accessToken-type", ++ "schemaVersion": "1.28", ++ "createEntities": [ ++ { ++ "client": { ++ "id": "client0" ++ } ++ }, ++ { ++ "clientEncryption": { ++ "id": "clientEncryption0", ++ "clientEncryptionOpts": { ++ "keyVaultClient": "client0", ++ "keyVaultNamespace": "keyvault.datakeys", ++ "kmsProviders": { ++ "azure": { ++ "accessToken": 0 ++ } ++ } ++ } ++ } ++ } ++ ], ++ "tests": [ ++ { ++ "description": "", ++ "operations": [] ++ } ++ ] ++} +diff --git a/test/unified-test-format/invalid/clientEncryptionOpts-kmsProviders-gcp-accessToken-type.json b/test/unified-test-format/invalid/clientEncryptionOpts-kmsProviders-gcp-accessToken-type.json +new file mode 100644 +index 00000000..2284e26c +--- /dev/null ++++ b/test/unified-test-format/invalid/clientEncryptionOpts-kmsProviders-gcp-accessToken-type.json +@@ -0,0 +1,31 @@ ++{ ++ "description": "clientEncryptionOpts-kmsProviders-gcp-accessToken-type", ++ "schemaVersion": "1.28", ++ "createEntities": [ ++ { ++ "client": { ++ "id": "client0" ++ } ++ }, ++ { ++ "clientEncryption": { ++ "id": "clientEncryption0", ++ "clientEncryptionOpts": { ++ "keyVaultClient": "client0", ++ "keyVaultNamespace": "keyvault.datakeys", ++ "kmsProviders": { ++ "gcp": { ++ "accessToken": 0 ++ } ++ } ++ } ++ } ++ } ++ ], ++ "tests": [ ++ { ++ "description": "", ++ "operations": [] ++ } ++ ] ++} From ee851ba974fcc5f9e1c39a5f6f4f9be89399aba8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Mar 2026 11:50:25 -0700 Subject: [PATCH 6/8] Bump astral-sh/setup-uv from 7.3.0 to 7.6.0 in the actions group (#2740) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/test-python.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 7c7793ed2..947e8e319 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -26,7 +26,7 @@ jobs: with: persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7 + uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: enable-cache: true python-version: "3.10" @@ -68,7 +68,7 @@ jobs: with: persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7 + uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: enable-cache: true python-version: ${{ matrix.python-version }} @@ -90,7 +90,7 @@ jobs: with: persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7 + uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: enable-cache: true python-version: "3.10" @@ -118,7 +118,7 @@ jobs: with: persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7 + uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: enable-cache: true python-version: "3.10" @@ -143,7 +143,7 @@ jobs: with: persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7 + uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: enable-cache: true python-version: "3.10" @@ -162,7 +162,7 @@ jobs: with: persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7 + uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: enable-cache: true python-version: "3.10" @@ -184,7 +184,7 @@ jobs: with: persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7 + uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: enable-cache: true python-version: "${{matrix.python}}" @@ -205,7 +205,7 @@ jobs: with: persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7 + uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: enable-cache: true python-version: "3.10" @@ -295,7 +295,7 @@ jobs: with: persist-credentials: false - name: Install uv - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7 + uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 with: python-version: "3.9" - id: setup-mongodb From db4db928d373261d8b087e78d6eca70d046e5461 Mon Sep 17 00:00:00 2001 From: Jib Date: Wed, 1 Apr 2026 11:51:53 -0400 Subject: [PATCH 7/8] PYTHON-5401: Add AI Generated Contributions Policy (#2696) Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .github/pull_request_template.md | 4 +-- CONTRIBUTING.md | 62 +++++++++++++++++--------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 2e1a132c9..b1f0987b3 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,8 +6,8 @@ If you are an external contributor and there is no JIRA ticket associated with y for the PR title. A MongoDB employee will create a JIRA ticket and edit the name and links as appropriate. Note on AI Contributions: -We do not accept pull requests that are primarily or substantially generated by AI tools (ChatGPT, Copilot, etc.). -All contributions must be written and understood by human contributors. +We only accept pull requests that are authored and submitted by human contributors who fully understand the changes they are proposing. +All contributions must be written and understood by human contributors. Please read about our policy in our contributing guide. --> [JIRA TICKET] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 86c5e6455..77888eb08 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -85,49 +85,53 @@ likelihood for getting review sooner shoots up. - `versionadded:: 3.11` - `versionchanged:: 3.5` -**Pull Request Template Breakdown** +### AI-Generated Contributions Policy -- **Github PR Title** +#### Our Stance - - The PR Title format should always be - `[JIRA-ID] : Jira Title or Blurb Summary`. +We only accept pull requests that are authored and submitted by human contributors who fully understand the changes they are proposing. Pull requests that are not clearly owned and understood by a human contributor may be closed. **All contributions must be submitted, reviewed, and understood by human contributors.** -- **JIRA LINK** +##### Why This Policy Exists -- Convenient link to the associated JIRA ticket. +At MongoDB, we understand the power and prevalence of AI tools in software development. With that being said, many MongoDB libraries are foundational tools used in production systems worldwide. The nature of these libraries requires: -- **Summary** +- **Deep domain expertise**: MongoDB's wire protocol, BSON specification, connection pooling, authentication mechanisms, and concurrency patterns require an understanding that AI alone cannot substantiate. - - Small blurb on why this is needed. The JIRA task should have - the more in-depth description, but this should still, at a - high level, give anyone looking an understanding of why the - PR has been checked in. +- **Long-term maintainability**: Contributors need to be able to explain *why* code is written a certain way, explain design decisions, and be available to iterate on their contributions. -- **Changes in this PR** +- **Security responsibility**: Authentication, credential handling, and TLS implementation cannot be left to probabilistic code generation. - - The explicit code changes that this PR is introducing. This - should be more specific than just the task name. (Unless the - task name is very clear). +##### What This Means for Contributors -- **Test Plan** +**Required:** - - Everything needs a test description. Describe what you did - to validate your changes actually worked; if you did - nothing, then document you did not test it. Aim to make - these steps reproducible by other engineers, specifically - with your primary reviewer in mind. +- Full understanding of every line of code you submit +- Ability to explain and defend your implementation choices +- Willingness to iterate and maintain your contributions -- **Screenshots** +**Encouraged:** - - Any images that provide more context to the PR. Usually, - these just coincide with the test plan. +- Using AI assistants as learning tools to understand concepts +- IDE autocomplete features that suggest standard patterns +- AI help for brainstorming approaches (but write the code yourself) +- Writing code using AI tools, reviewing each line and revising code as necessary. -- **Callouts or follow-up items** +**Not allowed:** - - This is a good place for identifying "to-dos" that you've - placed in the code (Must have an accompanying JIRA Ticket). - - Potential bugs that you are unsure how to test in the code. - - Opinions you want to receive about your code. +- Submitting PRs generated solely by AI tools +- Copy-pasting AI-generated code without full understanding + +##### Disclosure + +If you used AI assistance in any way during your contribution, please disclose what the AI assistant was used for in your PR description. We would love to know what tools developers have found useful in iterating in their day to day. + +##### Questions? + +If you're unsure whether your contribution complies with this policy, please ask for guidance within the scope of the PR and clarify any uncertainty. We're happy to guide contributors toward successful contributions. + +--- + +*This policy helps us maintain the reliability, security, and trustworthiness that production applications depend on. Thank you for understanding and for contributing thoughtfully to PyMongo.* ## Running Linters From 08b806fd8764e1fe07aa2582452752f3bea2e632 Mon Sep 17 00:00:00 2001 From: Jeffrey 'Alex' Clark Date: Tue, 7 Apr 2026 12:20:27 -0400 Subject: [PATCH 8/8] PYTHON-5768 Add AGENTS.md w/copilot instructions (#2744) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/copilot-instructions.md | 45 ++------------------------------- AGENTS.md | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 AGENTS.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index b67cb49ac..a8943d11a 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1,44 +1,3 @@ -When reviewing code, focus on: +Please see [AGENTS.md](../AGENTS.md). -## Security Critical Issues -- Check for hardcoded secrets, API keys, or credentials. -- Check for instances of potential method call injection, dynamic code execution, symbol injection or other code injection vulnerabilities. - -## Performance Red Flags -- Spot inefficient loops and algorithmic issues. -- Check for memory leaks and resource cleanup. - -## Code Quality Essentials -- Methods should be focused and appropriately sized. If a method is doing too much, suggest refactorings to split it up. -- Use clear, descriptive naming conventions. -- Avoid encapsulation violations and ensure proper separation of concerns. -- All public classes, modules, and methods should have clear documentation in Sphinx format. - -## PyMongo-specific Concerns -- Do not review files within `pymongo/synchronous` or files in `test/` that also have a file of the same name in `test/asynchronous` unless the reviewed changes include a `_IS_SYNC` statement. PyMongo generates these files from `pymongo/asynchronous` and `test/asynchronous` using `tools/synchro.py`. -- All asynchronous functions must not call any blocking I/O. - -## Review Style -- Be specific and actionable in feedback. -- Explain the "why" behind recommendations. -- Acknowledge good patterns when you see them. -- Ask clarifying questions when code intent is unclear. - -Always prioritize security vulnerabilities and performance issues that could impact users. - -Always suggest changes to improve readability and testability. For example, this suggestion seeks to make the code more readable, reusable, and testable: - -```python -# Instead of: -if user.email and "@" in user.email and len(user.email) > 5: - submit_button.enabled = True -else: - submit_button.enabled = False - -# Consider: -def valid_email(email): - return email and "@" in email and len(email) > 5 - - -submit_button.enabled = valid_email(user.email) -``` +Follow the repository instructions defined in `AGENTS.md` when working in this codebase. diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..b67cb49ac --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,44 @@ +When reviewing code, focus on: + +## Security Critical Issues +- Check for hardcoded secrets, API keys, or credentials. +- Check for instances of potential method call injection, dynamic code execution, symbol injection or other code injection vulnerabilities. + +## Performance Red Flags +- Spot inefficient loops and algorithmic issues. +- Check for memory leaks and resource cleanup. + +## Code Quality Essentials +- Methods should be focused and appropriately sized. If a method is doing too much, suggest refactorings to split it up. +- Use clear, descriptive naming conventions. +- Avoid encapsulation violations and ensure proper separation of concerns. +- All public classes, modules, and methods should have clear documentation in Sphinx format. + +## PyMongo-specific Concerns +- Do not review files within `pymongo/synchronous` or files in `test/` that also have a file of the same name in `test/asynchronous` unless the reviewed changes include a `_IS_SYNC` statement. PyMongo generates these files from `pymongo/asynchronous` and `test/asynchronous` using `tools/synchro.py`. +- All asynchronous functions must not call any blocking I/O. + +## Review Style +- Be specific and actionable in feedback. +- Explain the "why" behind recommendations. +- Acknowledge good patterns when you see them. +- Ask clarifying questions when code intent is unclear. + +Always prioritize security vulnerabilities and performance issues that could impact users. + +Always suggest changes to improve readability and testability. For example, this suggestion seeks to make the code more readable, reusable, and testable: + +```python +# Instead of: +if user.email and "@" in user.email and len(user.email) > 5: + submit_button.enabled = True +else: + submit_button.enabled = False + +# Consider: +def valid_email(email): + return email and "@" in email and len(email) > 5 + + +submit_button.enabled = valid_email(user.email) +```