PYTHON-4729 Drop support for MongoDB 3.6 (#1905)

This commit is contained in:
Shane Harvey 2024-10-09 09:58:20 -07:00 committed by GitHub
parent 5fa4380324
commit ac198af557
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 191 additions and 132 deletions

View File

@ -1014,33 +1014,6 @@ tasks:
TOPOLOGY: "server"
- func: "run doctests"
- name: "test-3.6-standalone"
tags: ["3.6", "standalone"]
commands:
- func: "bootstrap mongo-orchestration"
vars:
VERSION: "3.6"
TOPOLOGY: "server"
- func: "run tests"
- name: "test-3.6-replica_set"
tags: ["3.6", "replica_set"]
commands:
- func: "bootstrap mongo-orchestration"
vars:
VERSION: "3.6"
TOPOLOGY: "replica_set"
- func: "run tests"
- name: "test-3.6-sharded_cluster"
tags: ["3.6", "sharded_cluster"]
commands:
- func: "bootstrap mongo-orchestration"
vars:
VERSION: "3.6"
TOPOLOGY: "sharded_cluster"
- func: "run tests"
- name: "test-4.0-standalone"
tags: ["4.0", "standalone"]
commands:
@ -2186,10 +2159,6 @@ axes:
- id: mongodb-version
display_name: "MongoDB"
values:
- id: "3.6"
display_name: "MongoDB 3.6"
variables:
VERSION: "3.6"
- id: "4.0"
display_name: "MongoDB 4.0"
variables:
@ -2490,7 +2459,6 @@ buildvariants:
- ".4.4"
- ".4.2"
- ".4.0"
- ".3.6"
- matrix_name: "test-macos-arm64"
matrix_spec:
@ -2562,7 +2530,6 @@ buildvariants:
- ".4.4"
- ".4.2"
- ".4.0"
- ".3.6"
- matrix_name: "tests-pyopenssl"
matrix_spec:
@ -2657,19 +2624,22 @@ buildvariants:
display_name: "${compression} ${c-extensions} ${python-version} ${platform}"
tasks:
- "test-latest-standalone"
- "test-8.0-standalone"
- "test-7.0-standalone"
- "test-6.0-standalone"
- "test-5.0-standalone"
- "test-4.4-standalone"
- "test-4.2-standalone"
- "test-4.0-standalone"
rules:
# Server versions 3.6 and 4.0 support snappy and zlib.
# Server version 4.0 supports snappy and zlib but not zstd.
- if:
python-version: "*"
c-extensions: "*"
compression: ["snappy", "zlib"]
compression: ["zstd"]
then:
add_tasks:
remove_tasks:
- "test-4.0-standalone"
- "test-3.6-standalone"
- matrix_name: "tests-python-version-green-framework-rhel8"
matrix_spec:
@ -2734,7 +2704,7 @@ buildvariants:
matrix_spec:
platform: rhel8
storage-engine: "*"
python-version: 3.9
python-version: "3.9"
display_name: "Storage ${storage-engine} ${python-version} ${platform}"
rules:
- if:
@ -2751,7 +2721,6 @@ buildvariants:
- "test-4.4-standalone"
- "test-4.2-standalone"
- "test-4.0-standalone"
- "test-3.6-standalone"
- if:
# MongoDB 4.2 drops support for MMAPv1
platform: rhel8
@ -2761,8 +2730,6 @@ buildvariants:
add_tasks:
- "test-4.0-standalone"
- "test-4.0-replica_set"
- "test-3.6-standalone"
- "test-3.6-replica_set"
# enableTestCommands=0 tests on RHEL 8.4 (x86_64) with Python 3.9.
- matrix_name: "test-disableTestCommands"
@ -2881,6 +2848,9 @@ buildvariants:
tasks:
# Versioned API was introduced in MongoDB 4.7
- "test-latest-standalone"
- "test-8.0-standalone"
- "test-7.0-standalone"
- "test-6.0-standalone"
- "test-5.0-standalone"
- matrix_name: "ocsp-test"

View File

@ -14,7 +14,7 @@ a native Python driver for MongoDB. The `gridfs` package is a
[gridfs](https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.rst/)
implementation on top of `pymongo`.
PyMongo supports MongoDB 3.6, 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0.
PyMongo supports MongoDB 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0.
## Support / Feedback

View File

@ -5,6 +5,21 @@ Changes in Version 4.11.0
-------------------------
.. warning:: PyMongo 4.11 drops support for Python 3.8: Python 3.9+ or PyPy 3.9+ is now required.
.. warning:: PyMongo 4.11 drops support for MongoDB 3.6. PyMongo now supports MongoDB 4.0+.
Driver support for MongoDB 3.6 reached end of life in April 2024.
PyMongo 4.11 brings a number of changes including:
- Dropped support for Python 3.8.
- Dropped support for MongoDB 3.6.
Issues Resolved
...............
See the `PyMongo 4.11 release notes in JIRA`_ for the list of resolved issues
in this release.
.. _PyMongo 4.11 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=40784
Changes in Version 4.10.1
-------------------------

View File

@ -6,14 +6,14 @@ Also see the :ref:`TLSErrors` section.
Server reports wire version X, PyMongo requires Y
-------------------------------------------------
When one attempts to connect to a <=3.4 version server, PyMongo will throw the following error::
When one attempts to connect to a <=3.6 version server, PyMongo will throw the following error::
>>> client.admin.command('ping')
...
pymongo.errors.ConfigurationError: Server at localhost:27017 reports wire version 5, but this version of PyMongo requires at least 6 (MongoDB 3.6).
pymongo.errors.ConfigurationError: Server at localhost:27017 reports wire version 6, but this version of PyMongo requires at least 7 (MongoDB 4.0).
This is caused by the driver being too new for the server it is being run against.
To resolve this issue either upgrade your database to version >= 3.6 or downgrade to PyMongo 3.x which supports MongoDB >= 2.6.
To resolve this issue either upgrade your database to version >= 4.0 or downgrade to an early version of PyMongo which supports MongoDB < 4.0.
'Cursor' object has no attribute '_Cursor__killed'

View File

@ -97,9 +97,8 @@ the "MongoDB Challenge-Response" protocol::
Default Authentication Mechanism
--------------------------------
If no mechanism is specified, PyMongo automatically SCRAM-SHA-1 when connected
to MongoDB 3.6 and negotiates the mechanism to use (SCRAM-SHA-1
or SCRAM-SHA-256) when connected to MongoDB 4.0+.
If no mechanism is specified, PyMongo automatically negotiates the mechanism to use (SCRAM-SHA-1
or SCRAM-SHA-256) with the MongoDB server.
Default Database and "authSource"
---------------------------------

View File

@ -1960,20 +1960,15 @@ class AsyncCollection(common.BaseObject, Generic[_DocumentType]):
collation: Optional[Collation],
) -> int:
"""Internal count command helper."""
# XXX: "ns missing" checks can be removed when we drop support for
# MongoDB 3.0, see SERVER-17051.
res = await self._command(
conn,
cmd,
read_preference=read_preference,
allowable_errors=["ns missing"],
codec_options=self._write_response_codec_options,
read_concern=self.read_concern,
collation=collation,
session=session,
)
if res.get("errmsg", "") == "ns missing":
return 0
return int(res["n"])
async def _aggregate_one_result(

View File

@ -498,9 +498,8 @@ class AsyncMongoClient(common.BaseObject, Generic[_DocumentType]):
- `authSource`: The database to authenticate on. Defaults to the
database specified in the URI, if provided, or to "admin".
- `authMechanism`: See :data:`~pymongo.auth.MECHANISMS` for options.
If no mechanism is specified, PyMongo automatically SCRAM-SHA-1
when connected to MongoDB 3.6 and negotiates the mechanism to use
(SCRAM-SHA-1 or SCRAM-SHA-256) when connected to MongoDB 4.0+.
If no mechanism is specified, PyMongo automatically negotiates the
mechanism to use (SCRAM-SHA-1 or SCRAM-SHA-256) with the MongoDB server.
- `authMechanismProperties`: Used to specify authentication mechanism
specific options. To specify the service name for GSSAPI
authentication pass authMechanismProperties='SERVICE_NAME:<service

View File

@ -66,8 +66,8 @@ MAX_WIRE_VERSION = 0
MAX_WRITE_BATCH_SIZE = 1000
# What this version of PyMongo supports.
MIN_SUPPORTED_SERVER_VERSION = "3.6"
MIN_SUPPORTED_WIRE_VERSION = 6
MIN_SUPPORTED_SERVER_VERSION = "4.0"
MIN_SUPPORTED_WIRE_VERSION = 7
# MongoDB 8.0
MAX_SUPPORTED_WIRE_VERSION = 25

View File

@ -1959,20 +1959,15 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
collation: Optional[Collation],
) -> int:
"""Internal count command helper."""
# XXX: "ns missing" checks can be removed when we drop support for
# MongoDB 3.0, see SERVER-17051.
res = self._command(
conn,
cmd,
read_preference=read_preference,
allowable_errors=["ns missing"],
codec_options=self._write_response_codec_options,
read_concern=self.read_concern,
collation=collation,
session=session,
)
if res.get("errmsg", "") == "ns missing":
return 0
return int(res["n"])
def _aggregate_one_result(

View File

@ -496,9 +496,8 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
- `authSource`: The database to authenticate on. Defaults to the
database specified in the URI, if provided, or to "admin".
- `authMechanism`: See :data:`~pymongo.auth.MECHANISMS` for options.
If no mechanism is specified, PyMongo automatically SCRAM-SHA-1
when connected to MongoDB 3.6 and negotiates the mechanism to use
(SCRAM-SHA-1 or SCRAM-SHA-256) when connected to MongoDB 4.0+.
If no mechanism is specified, PyMongo automatically negotiates the
mechanism to use (SCRAM-SHA-1 or SCRAM-SHA-256) with the MongoDB server.
- `authMechanismProperties`: Used to specify authentication mechanism
specific options. To specify the service name for GSSAPI
authentication pass authMechanismProperties='SERVICE_NAME:<service

View File

@ -99,7 +99,7 @@ from pymongo.asynchronous.pool import (
from pymongo.asynchronous.settings import TOPOLOGY_TYPE
from pymongo.asynchronous.topology import _ErrorContext
from pymongo.client_options import ClientOptions
from pymongo.common import _UUID_REPRESENTATIONS, CONNECT_TIMEOUT, has_c
from pymongo.common import _UUID_REPRESENTATIONS, CONNECT_TIMEOUT, MIN_SUPPORTED_WIRE_VERSION, has_c
from pymongo.compression_support import _have_snappy, _have_zstd
from pymongo.driver_info import DriverInfo
from pymongo.errors import (
@ -2455,8 +2455,8 @@ class TestMongoClientFailover(AsyncMockClientTest):
self.addAsyncCleanup(c.close)
# Set host-specific information so we can test whether it is reset.
c.set_wire_version_range("a:1", 2, 6)
c.set_wire_version_range("b:2", 2, 7)
c.set_wire_version_range("a:1", 2, MIN_SUPPORTED_WIRE_VERSION)
c.set_wire_version_range("b:2", 2, MIN_SUPPORTED_WIRE_VERSION + 1)
await (await c._get_topology()).select_servers(writable_server_selector, _Op.TEST)
wait_until(lambda: len(c.nodes) == 2, "connect")
@ -2480,7 +2480,7 @@ class TestMongoClientFailover(AsyncMockClientTest):
sd_b = server_b.description
self.assertEqual(SERVER_TYPE.RSSecondary, sd_b.server_type)
self.assertEqual(2, sd_b.min_wire_version)
self.assertEqual(7, sd_b.max_wire_version)
self.assertEqual(MIN_SUPPORTED_WIRE_VERSION + 1, sd_b.max_wire_version)
async def test_network_error_on_query(self):
async def callback(client):

View File

@ -66,7 +66,7 @@
"$oid": "000000000000000000000002"
},
"minWireVersion": 0,
"maxWireVersion": 21
"maxWireVersion": 7
}
]
],

View File

@ -25,7 +25,7 @@ try:
except ImportError:
_HAVE_MOCKUPDB = False
from pymongo import MongoClient
from pymongo import common
from pymongo.errors import ServerSelectionTimeoutError
pytestmark = pytest.mark.mockupdb
@ -39,7 +39,7 @@ class TestAuthRecoveringMember(PyMongoTestCase):
"ismaster",
{
"minWireVersion": 2,
"maxWireVersion": 6,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
"ismaster": False,
"secondary": False,
"setName": "rs",

View File

@ -30,13 +30,16 @@ except ImportError:
from bson import Timestamp
from pymongo import DeleteMany, InsertOne, MongoClient, UpdateOne
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.errors import OperationFailure
pytestmark = pytest.mark.mockupdb
class TestClusterTime(PyMongoTestCase):
def cluster_time_conversation(self, callback, replies, max_wire_version=6):
def cluster_time_conversation(
self, callback, replies, max_wire_version=MIN_SUPPORTED_WIRE_VERSION
):
cluster_time = Timestamp(0, 0)
server = MockupDB()
@ -110,7 +113,7 @@ class TestClusterTime(PyMongoTestCase):
cluster_time = Timestamp(0, 0)
reply = {
"minWireVersion": 0,
"maxWireVersion": 6,
"maxWireVersion": MIN_SUPPORTED_WIRE_VERSION,
"$clusterTime": {"clusterTime": cluster_time},
}

View File

@ -29,6 +29,7 @@ except ImportError:
from bson.objectid import ObjectId
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.errors import OperationFailure
pytestmark = pytest.mark.mockupdb
@ -74,7 +75,7 @@ class TestRetryableErrorCodeCatch(PyMongoTestCase):
server = MockupDB()
server.run()
self.addCleanup(server.stop)
server.autoresponds("ismaster", maxWireVersion=6)
server.autoresponds("ismaster", maxWireVersion=MIN_SUPPORTED_WIRE_VERSION)
client = self.simple_client(server.uri)

View File

@ -29,6 +29,7 @@ except ImportError:
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
pytestmark = pytest.mark.mockupdb
@ -39,7 +40,7 @@ class TestCursorNamespace(PyMongoTestCase):
@classmethod
def setUpClass(cls):
cls.server = MockupDB(auto_ismaster={"maxWireVersion": 6})
cls.server = MockupDB(auto_ismaster={"maxWireVersion": 7})
cls.server.run()
cls.client = cls.unmanaged_simple_client(cls.server.uri)
@ -95,7 +96,7 @@ class TestKillCursorsNamespace(PyMongoTestCase):
@classmethod
def setUpClass(cls):
cls.server = MockupDB(auto_ismaster={"maxWireVersion": 6})
cls.server = MockupDB(auto_ismaster={"maxWireVersion": MIN_SUPPORTED_WIRE_VERSION})
cls.server.run()
cls.client = cls.unmanaged_simple_client(cls.server.uri)

View File

@ -29,7 +29,7 @@ except ImportError:
_HAVE_MOCKUPDB = False
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
pytestmark = pytest.mark.mockupdb
@ -43,7 +43,11 @@ class TestGetmoreSharded(PyMongoTestCase):
for server in servers:
server.subscribe(q.put)
server.autoresponds(
"ismaster", ismaster=True, msg="isdbgrid", minWireVersion=2, maxWireVersion=6
"ismaster",
ismaster=True,
msg="isdbgrid",
minWireVersion=2,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
server.run()
self.addCleanup(server.stop)

View File

@ -28,6 +28,7 @@ except ImportError:
from bson.objectid import ObjectId
from pymongo import MongoClient, has_c
from pymongo import version as pymongo_version
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.errors import OperationFailure
from pymongo.server_api import ServerApi, ServerApiVersion
@ -101,7 +102,12 @@ class TestHandshake(unittest.TestCase):
hosts = [server.address_string for server in (primary, secondary)]
primary_response = OpReply(
"ismaster", True, setName="rs", hosts=hosts, minWireVersion=2, maxWireVersion=6
"ismaster",
True,
setName="rs",
hosts=hosts,
minWireVersion=2,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
error_response = OpReply(0, errmsg="Cache Reader No keys found for HMAC ...", code=211)
@ -112,7 +118,7 @@ class TestHandshake(unittest.TestCase):
hosts=hosts,
secondary=True,
minWireVersion=2,
maxWireVersion=6,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
client = MongoClient(
@ -179,7 +185,9 @@ class TestHandshake(unittest.TestCase):
server.run()
self.addCleanup(server.stop)
primary_response = OpReply("ismaster", True, minWireVersion=2, maxWireVersion=6)
primary_response = OpReply(
"ismaster", True, minWireVersion=2, maxWireVersion=MIN_SUPPORTED_WIRE_VERSION
)
client = MongoClient(server.uri, username="username", password="password")
self.addCleanup(client.close)
@ -213,7 +221,7 @@ class TestHandshake(unittest.TestCase):
saslSupportedMechs=["SCRAM-SHA-256"],
speculativeAuthenticate=auth,
minWireVersion=2,
maxWireVersion=6,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
# Authentication should immediately fail with:
# OperationFailure: Server returned an invalid nonce.
@ -240,7 +248,12 @@ class TestHandshake(unittest.TestCase):
def test_handshake_max_wire(self):
server = MockupDB()
primary_response = {"hello": 1, "ok": 1, "minWireVersion": 0, "maxWireVersion": 6}
primary_response = {
"hello": 1,
"ok": 1,
"minWireVersion": 0,
"maxWireVersion": MIN_SUPPORTED_WIRE_VERSION,
}
self.found_auth_msg = False
def responder(request):

View File

@ -27,7 +27,7 @@ except ImportError:
_HAVE_MOCKUPDB = False
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
pytestmark = pytest.mark.mockupdb
@ -43,11 +43,15 @@ class TestInitialIsMaster(PyMongoTestCase):
# A single ismaster is enough for the client to be connected.
self.assertFalse(client.nodes)
server.receives("ismaster").ok(ismaster=True, minWireVersion=2, maxWireVersion=6)
server.receives("ismaster").ok(
ismaster=True, minWireVersion=2, maxWireVersion=MIN_SUPPORTED_WIRE_VERSION
)
wait_until(lambda: client.nodes, "update nodes", timeout=1)
# At least 10 seconds before next heartbeat.
server.receives("ismaster").ok(ismaster=True, minWireVersion=2, maxWireVersion=6)
server.receives("ismaster").ok(
ismaster=True, minWireVersion=2, maxWireVersion=MIN_SUPPORTED_WIRE_VERSION
)
self.assertGreaterEqual(time.time() - start, 10)

View File

@ -29,13 +29,14 @@ except ImportError:
from bson import SON
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
pytestmark = pytest.mark.mockupdb
class TestListIndexes(PyMongoTestCase):
def test_list_indexes_command(self):
server = MockupDB(auto_ismaster={"maxWireVersion": 6})
server = MockupDB(auto_ismaster={"maxWireVersion": MIN_SUPPORTED_WIRE_VERSION})
server.run()
self.addCleanup(server.stop)
client = self.simple_client(server.uri)

View File

@ -26,7 +26,7 @@ except ImportError:
_HAVE_MOCKUPDB = False
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
pytestmark = pytest.mark.mockupdb
@ -34,7 +34,9 @@ pytestmark = pytest.mark.mockupdb
class TestMaxStalenessMongos(PyMongoTestCase):
def test_mongos(self):
mongos = MockupDB()
mongos.autoresponds("ismaster", maxWireVersion=6, ismaster=True, msg="isdbgrid")
mongos.autoresponds(
"ismaster", maxWireVersion=MIN_SUPPORTED_WIRE_VERSION, ismaster=True, msg="isdbgrid"
)
mongos.run()
self.addCleanup(mongos.stop)

View File

@ -31,8 +31,6 @@ except ImportError:
from operations import upgrades # type: ignore[import]
from pymongo import MongoClient
pytestmark = pytest.mark.mockupdb

View File

@ -28,6 +28,7 @@ except ImportError:
from operations import operations # type: ignore[import]
from pymongo import MongoClient, ReadPreference
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.read_preferences import (
_MONGOS_MODES,
make_read_preference,
@ -41,7 +42,11 @@ class TestMongosCommandReadMode(unittest.TestCase):
def test_aggregate(self):
server = MockupDB()
server.autoresponds(
"ismaster", ismaster=True, msg="isdbgrid", minWireVersion=2, maxWireVersion=6
"ismaster",
ismaster=True,
msg="isdbgrid",
minWireVersion=2,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
self.addCleanup(server.stop)
server.run()
@ -76,7 +81,11 @@ def create_mongos_read_mode_test(mode, operation):
self.addCleanup(server.stop)
server.run()
server.autoresponds(
"ismaster", ismaster=True, msg="isdbgrid", minWireVersion=2, maxWireVersion=6
"ismaster",
ismaster=True,
msg="isdbgrid",
minWireVersion=2,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
pref = make_read_preference(read_pref_mode_from_name(mode), tag_sets=None)

View File

@ -26,6 +26,7 @@ except ImportError:
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.errors import ConnectionFailure
from pymongo.topology_description import TOPOLOGY_TYPE
@ -44,7 +45,11 @@ class TestNetworkDisconnectPrimary(unittest.TestCase):
hosts = [server.address_string for server in (primary, secondary)]
primary_response = OpReply(
ismaster=True, setName="rs", hosts=hosts, minWireVersion=2, maxWireVersion=6
ismaster=True,
setName="rs",
hosts=hosts,
minWireVersion=2,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
primary.autoresponds("ismaster", primary_response)
secondary.autoresponds(
@ -54,7 +59,7 @@ class TestNetworkDisconnectPrimary(unittest.TestCase):
setName="rs",
hosts=hosts,
minWireVersion=2,
maxWireVersion=6,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
client = MongoClient(primary.uri, replicaSet="rs")

View File

@ -30,7 +30,8 @@ except ImportError:
from operations import operations # type: ignore[import]
from pymongo import MongoClient, ReadPreference
from pymongo import ReadPreference
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.read_preferences import (
_MONGOS_MODES,
make_read_preference,
@ -66,7 +67,7 @@ class TestOpMsgMongos(OpMsgReadPrefBase):
"ismaster": True,
"msg": "isdbgrid", # Mongos.
"minWireVersion": 2,
"maxWireVersion": 6,
"maxWireVersion": MIN_SUPPORTED_WIRE_VERSION,
}
cls.primary = MockupDB(auto_ismaster=auto_ismaster)
cls.primary.run()
@ -93,7 +94,7 @@ class TestOpMsgReplicaSet(OpMsgReadPrefBase):
"setName": "rs",
"hosts": hosts,
"minWireVersion": 2,
"maxWireVersion": 6,
"maxWireVersion": MIN_SUPPORTED_WIRE_VERSION,
}
cls.primary.autoresponds(CommandBase("ismaster"), primary_ismaster)
secondary_ismaster = copy.copy(primary_ismaster)
@ -134,7 +135,7 @@ class TestOpMsgSingle(OpMsgReadPrefBase):
auto_ismaster = {
"ismaster": True,
"minWireVersion": 2,
"maxWireVersion": 6,
"maxWireVersion": MIN_SUPPORTED_WIRE_VERSION,
}
cls.primary = MockupDB(auto_ismaster=auto_ismaster)
cls.primary.run()

View File

@ -29,7 +29,7 @@ except ImportError:
from bson import SON
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.read_preferences import (
Nearest,
Primary,
@ -46,7 +46,11 @@ class TestQueryAndReadModeSharded(PyMongoTestCase):
"""Test OP_MSG sends non-primary $readPreference and never $query."""
server = MockupDB()
server.autoresponds(
"ismaster", ismaster=True, msg="isdbgrid", minWireVersion=2, maxWireVersion=6
"ismaster",
ismaster=True,
msg="isdbgrid",
minWireVersion=2,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
server.run()
self.addCleanup(server.stop)

View File

@ -30,7 +30,7 @@ except ImportError:
from operations import operations # type: ignore[import]
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.errors import ConnectionFailure
from pymongo.operations import _Op
from pymongo.server_type import SERVER_TYPE
@ -50,7 +50,9 @@ class TestResetAndRequestCheck(PyMongoTestCase):
def responder(request):
self.ismaster_time = time.time()
return request.ok(ismaster=True, minWireVersion=2, maxWireVersion=6)
return request.ok(
ismaster=True, minWireVersion=2, maxWireVersion=MIN_SUPPORTED_WIRE_VERSION
)
self.server.autoresponds("ismaster", responder)
self.server.run()

View File

@ -32,6 +32,7 @@ except ImportError:
from operations import operations # type: ignore[import]
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
pytestmark = pytest.mark.mockupdb
@ -45,7 +46,12 @@ class TestSlaveOkayRS(unittest.TestCase):
hosts = [server.address_string for server in (self.primary, self.secondary)]
self.primary.autoresponds(
"ismaster", ismaster=True, setName="rs", hosts=hosts, minWireVersion=2, maxWireVersion=6
"ismaster",
ismaster=True,
setName="rs",
hosts=hosts,
minWireVersion=2,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)
self.secondary.autoresponds(
"ismaster",
@ -54,7 +60,7 @@ class TestSlaveOkayRS(unittest.TestCase):
setName="rs",
hosts=hosts,
minWireVersion=2,
maxWireVersion=6,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
)

View File

@ -36,6 +36,7 @@ except ImportError:
from operations import operations # type: ignore[import]
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.read_preferences import make_read_preference, read_pref_mode_from_name
pytestmark = pytest.mark.mockupdb
@ -52,7 +53,11 @@ class TestSlaveOkaySharded(unittest.TestCase):
server.run()
self.addCleanup(server.stop)
server.autoresponds(
"ismaster", minWireVersion=2, maxWireVersion=6, ismaster=True, msg="isdbgrid"
"ismaster",
minWireVersion=2,
maxWireVersion=MIN_SUPPORTED_WIRE_VERSION,
ismaster=True,
msg="isdbgrid",
)
self.mongoses_uri = f"mongodb://{self.mongos1.address_string},{self.mongos2.address_string}"

View File

@ -35,6 +35,7 @@ except ImportError:
from operations import operations # type: ignore[import]
from pymongo import MongoClient
from pymongo.common import MIN_SUPPORTED_WIRE_VERSION
from pymongo.read_preferences import make_read_preference, read_pref_mode_from_name
from pymongo.topology_description import TOPOLOGY_TYPE
@ -57,7 +58,7 @@ def create_slave_ok_single_test(mode, server_type, ismaster, operation):
def test(self):
ismaster_with_version = ismaster.copy()
ismaster_with_version["minWireVersion"] = 2
ismaster_with_version["maxWireVersion"] = 6
ismaster_with_version["maxWireVersion"] = MIN_SUPPORTED_WIRE_VERSION
self.server.autoresponds("ismaster", **ismaster_with_version)
self.assertIn(
operation.op_type, ("always-use-secondary", "may-use-secondary", "must-use-primary")

View File

@ -87,7 +87,7 @@ from bson.son import SON
from bson.tz_util import utc
from pymongo import event_loggers, message, monitoring
from pymongo.client_options import ClientOptions
from pymongo.common import _UUID_REPRESENTATIONS, CONNECT_TIMEOUT, has_c
from pymongo.common import _UUID_REPRESENTATIONS, CONNECT_TIMEOUT, MIN_SUPPORTED_WIRE_VERSION, has_c
from pymongo.compression_support import _have_snappy, _have_zstd
from pymongo.driver_info import DriverInfo
from pymongo.errors import (
@ -2411,8 +2411,8 @@ class TestMongoClientFailover(MockClientTest):
self.addCleanup(c.close)
# Set host-specific information so we can test whether it is reset.
c.set_wire_version_range("a:1", 2, 6)
c.set_wire_version_range("b:2", 2, 7)
c.set_wire_version_range("a:1", 2, MIN_SUPPORTED_WIRE_VERSION)
c.set_wire_version_range("b:2", 2, MIN_SUPPORTED_WIRE_VERSION + 1)
(c._get_topology()).select_servers(writable_server_selector, _Op.TEST)
wait_until(lambda: len(c.nodes) == 2, "connect")
@ -2436,7 +2436,7 @@ class TestMongoClientFailover(MockClientTest):
sd_b = server_b.description
self.assertEqual(SERVER_TYPE.RSSecondary, sd_b.server_type)
self.assertEqual(2, sd_b.min_wire_version)
self.assertEqual(7, sd_b.max_wire_version)
self.assertEqual(MIN_SUPPORTED_WIRE_VERSION + 1, sd_b.max_wire_version)
def test_network_error_on_query(self):
def callback(client):

View File

@ -250,7 +250,12 @@ class TestClusterTimeComparison(unittest.TestCase):
got_hello(
t,
("host", 27017),
{"ok": 1, "minWireVersion": 0, "maxWireVersion": 6, "$clusterTime": new},
{
"ok": 1,
"minWireVersion": 0,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
"$clusterTime": new,
},
)
actual = t.max_cluster_time()

View File

@ -118,7 +118,7 @@ class TestServerDescription(unittest.TestCase):
"maxBsonObjectSize": 2,
"maxWriteBatchSize": 3,
"minWireVersion": 4,
"maxWireVersion": 5,
"maxWireVersion": 25,
"setName": "rs",
}
)
@ -130,7 +130,7 @@ class TestServerDescription(unittest.TestCase):
self.assertEqual(2, s.max_bson_size)
self.assertEqual(3, s.max_write_batch_size)
self.assertEqual(4, s.min_wire_version)
self.assertEqual(5, s.max_wire_version)
self.assertEqual(25, s.max_wire_version)
def test_default_max_message_size(self):
s = parse_hello_response({"ok": 1, HelloCompat.LEGACY_CMD: True, "maxBsonObjectSize": 2})

View File

@ -133,7 +133,7 @@ class TestSingleServerTopology(TopologyTest):
HelloCompat.LEGACY_CMD: True,
"hosts": ["a"],
"setName": "rs",
"maxWireVersion": 6,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
},
),
(
@ -144,12 +144,17 @@ class TestSingleServerTopology(TopologyTest):
"secondary": True,
"hosts": ["a"],
"setName": "rs",
"maxWireVersion": 6,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
},
),
(
SERVER_TYPE.Mongos,
{"ok": 1, HelloCompat.LEGACY_CMD: True, "msg": "isdbgrid", "maxWireVersion": 6},
{
"ok": 1,
HelloCompat.LEGACY_CMD: True,
"msg": "isdbgrid",
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
},
),
(
SERVER_TYPE.RSArbiter,
@ -159,14 +164,28 @@ class TestSingleServerTopology(TopologyTest):
"arbiterOnly": True,
"hosts": ["a"],
"setName": "rs",
"maxWireVersion": 6,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
},
),
(
SERVER_TYPE.Standalone,
{
"ok": 1,
HelloCompat.LEGACY_CMD: True,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
},
),
(SERVER_TYPE.Standalone, {"ok": 1, HelloCompat.LEGACY_CMD: True, "maxWireVersion": 6}),
# A "slave" in a master-slave deployment.
# This replication type was removed in MongoDB
# 4.0.
(SERVER_TYPE.Standalone, {"ok": 1, HelloCompat.LEGACY_CMD: False, "maxWireVersion": 6}),
(
SERVER_TYPE.Standalone,
{
"ok": 1,
HelloCompat.LEGACY_CMD: False,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
},
),
]:
t = create_mock_topology(direct_connection=True)
@ -213,7 +232,10 @@ class TestSingleServerTopology(TopologyTest):
class TestMonitor(Monitor):
def _check_with_socket(self, *args, **kwargs):
if available:
return (Hello({"ok": 1, "maxWireVersion": 6}), round_trip_time)
return (
Hello({"ok": 1, "maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION}),
round_trip_time,
)
else:
raise AutoReconnect("mock monitor error")
@ -531,12 +553,12 @@ class TestMultiServerTopology(TopologyTest):
"setName": "rs",
"hosts": ["a"],
"minWireVersion": 1,
"maxWireVersion": 6,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
},
)
self.assertEqual(server.description.min_wire_version, 1)
self.assertEqual(server.description.max_wire_version, 6)
self.assertEqual(server.description.max_wire_version, 7)
t.select_servers(any_server_selector, _Op.TEST)
# Incompatible.
@ -607,7 +629,7 @@ class TestMultiServerTopology(TopologyTest):
HelloCompat.LEGACY_CMD: True,
"setName": "rs",
"hosts": ["a", "b"],
"maxWireVersion": 6,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
"maxWriteBatchSize": 1,
},
)
@ -621,7 +643,7 @@ class TestMultiServerTopology(TopologyTest):
"secondary": True,
"setName": "rs",
"hosts": ["a", "b"],
"maxWireVersion": 6,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
"maxWriteBatchSize": 2,
},
)
@ -638,7 +660,7 @@ class TestMultiServerTopology(TopologyTest):
HelloCompat.LEGACY_CMD: True,
"setName": "rs",
"hosts": ["a", "b"],
"maxWireVersion": 6,
"maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION,
"maxWriteBatchSize": 2,
},
)
@ -735,7 +757,7 @@ class TestTopologyErrors(TopologyTest):
def _check_with_socket(self, *args, **kwargs):
hello_count[0] += 1
if hello_count[0] == 1:
return Hello({"ok": 1, "maxWireVersion": 6}), 0
return Hello({"ok": 1, "maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION}), 0
else:
raise AutoReconnect("mock monitor error")
@ -757,7 +779,7 @@ class TestTopologyErrors(TopologyTest):
def _check_with_socket(self, *args, **kwargs):
hello_count[0] += 1
if hello_count[0] in (1, 3):
return Hello({"ok": 1, "maxWireVersion": 6}), 0
return Hello({"ok": 1, "maxWireVersion": common.MIN_SUPPORTED_WIRE_VERSION}), 0
else:
raise AutoReconnect(f"mock monitor error #{hello_count[0]}")

View File

@ -26,7 +26,7 @@ from test.pymongo_mocks import DummyMonitor
from test.utils import MockPool, parse_read_preference
from bson import json_util
from pymongo.common import HEARTBEAT_FREQUENCY, clean_node
from pymongo.common import HEARTBEAT_FREQUENCY, MIN_SUPPORTED_WIRE_VERSION, clean_node
from pymongo.errors import AutoReconnect, ConfigurationError
from pymongo.hello import Hello, HelloCompat
from pymongo.operations import _Op
@ -85,7 +85,7 @@ def make_server_description(server, hosts):
if field in server:
hello_response[field] = server[field]
hello_response.setdefault("maxWireVersion", 6)
hello_response.setdefault("maxWireVersion", MIN_SUPPORTED_WIRE_VERSION)
# Sets _last_update_time to now.
sd = ServerDescription(