Skip to content

Commit 2548696

Browse files
committed
PYTHON-5808 Drop support for MongoDB 4.2
Bump minimum supported server version to MongoDB 4.4 (wire version 9). Remove dead code paths that only applied to wire version < 8 servers, including the legacy OP_GET_MORE protocol, the use_command dispatch mechanism, and the from_command response field.
1 parent f65a451 commit 2548696

36 files changed

Lines changed: 497 additions & 862 deletions

.evergreen/generated_configs/tasks.yml

Lines changed: 462 additions & 590 deletions
Large diffs are not rendered by default.

.evergreen/generated_configs/variants.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,6 @@ buildvariants:
491491
- rhel87-small
492492

493493
# Server version tests
494-
- name: mongodb-v4.2
495-
tasks:
496-
- name: .server-version
497-
display_name: "* MongoDB v4.2"
498-
run_on:
499-
- rhel87-small
500-
expansions:
501-
VERSION: "4.2"
502-
tags: [coverage_tag]
503494
- name: mongodb-v4.4
504495
tasks:
505496
- name: .server-version

.evergreen/scripts/generate_config_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Globals
2222
##############
2323

24-
ALL_VERSIONS = ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "rapid", "latest"]
24+
ALL_VERSIONS = ["4.4", "5.0", "6.0", "7.0", "8.0", "rapid", "latest"]
2525
CPYTHONS = ["3.10", "3.11", "3.12", "3.13", "3.14t", "3.14"]
2626
PYPYS = ["pypy3.11"]
2727
MIN_SUPPORT_VERSIONS = ["3.9", "pypy3.9", "pypy3.10"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ a native Python driver for MongoDB, offering both synchronous and asynchronous A
1515
[gridfs](https://github.com/mongodb/specifications/blob/master/source/gridfs/gridfs-spec.md/)
1616
implementation on top of `pymongo`.
1717

18-
PyMongo supports MongoDB 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0. PyMongo follows [semantic versioning](https://semver.org/spec/v2.0.0.html) for its releases.
18+
PyMongo supports MongoDB 4.4, 5.0, 6.0, 7.0, and 8.0. PyMongo follows [semantic versioning](https://semver.org/spec/v2.0.0.html) for its releases.
1919

2020
## Documentation
2121

doc/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
Changes in Version 4.18.0
55
-------------------------
66

7+
- Dropped support for MongoDB 4.2. PyMongo now requires MongoDB 4.4 or later.
78
- Improved TLS connection performance by reusing TLS sessions across connections
89
to the same server, avoiding a full handshake on each new connection.
910
Session resumption is supported on all Python versions for synchronous clients

pymongo/asynchronous/aggregation.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,9 @@ async def get_cursor(
140140
cmd = {"aggregate": self._aggregation_target, "pipeline": self._pipeline}
141141
cmd.update(self._options)
142142

143-
# Apply this target's read concern if:
144-
# readConcern has not been specified as a kwarg and either
145-
# - server version is >= 4.2 or
146-
# - server version is >= 3.2 and pipeline doesn't use $out
147-
if ("readConcern" not in cmd) and (
148-
not self._performs_write or (conn.max_wire_version >= 8)
149-
):
143+
# Apply this target's read concern if readConcern has not been specified as a kwarg.
144+
# $out/$merge pipelines also support readConcern on all supported server versions (4.4+).
145+
if "readConcern" not in cmd:
150146
read_concern = self._target.read_concern
151147
else:
152148
read_concern = None

pymongo/asynchronous/bulk.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,6 @@ async def execute_no_results(
576576
raise ConfigurationError(
577577
"Must be connected to MongoDB 4.4+ to use hint on unacknowledged delete commands."
578578
)
579-
if unack and self.uses_hint_update and conn.max_wire_version < 8:
580-
raise ConfigurationError(
581-
"Must be connected to MongoDB 4.2+ to use hint on unacknowledged update commands."
582-
)
583579
if unack and self.uses_sort and conn.max_wire_version < 25:
584580
raise ConfigurationError(
585581
"Must be connected to MongoDB 8.0+ to use sort on unacknowledged update commands."

pymongo/asynchronous/collection.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,10 +1010,6 @@ async def _update(
10101010
else:
10111011
update_doc["arrayFilters"] = array_filters
10121012
if hint is not None:
1013-
if not acknowledged and conn.max_wire_version < 8:
1014-
raise ConfigurationError(
1015-
"Must be connected to MongoDB 4.2+ to use hint on unacknowledged update commands."
1016-
)
10171013
if not isinstance(hint, str):
10181014
hint = helpers_shared._index_document(hint)
10191015
update_doc["hint"] = hint
@@ -3295,14 +3291,6 @@ async def _find_and_modify_helper(
32953291
)
32963292
cmd["arrayFilters"] = list(array_filters)
32973293
if hint is not None:
3298-
if conn.max_wire_version < 8:
3299-
raise ConfigurationError(
3300-
"Must be connected to MongoDB 4.2+ to use hint on find and modify commands."
3301-
)
3302-
elif not acknowledged and conn.max_wire_version < 9:
3303-
raise ConfigurationError(
3304-
"Must be connected to MongoDB 4.4+ to use hint on unacknowledged find and modify commands."
3305-
)
33063294
cmd["hint"] = hint
33073295
out = await self._command(
33083296
conn,

pymongo/asynchronous/mongo_client.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,14 +1804,6 @@ async def _checkout(
18041804
):
18051805
session._pin(server, conn)
18061806
err_handler.contribute_socket(conn)
1807-
if (
1808-
self._encrypter
1809-
and not self._encrypter._bypass_auto_encryption
1810-
and conn.max_wire_version < 8
1811-
):
1812-
raise ConfigurationError(
1813-
"Auto-encryption requires a minimum MongoDB version of 4.2"
1814-
)
18151807
yield conn
18161808

18171809
async def _select_server(

pymongo/asynchronous/server.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,18 @@ async def run_operation(
157157
assert listeners is not None
158158
start = datetime.now()
159159

160-
use_cmd = operation.use_command(conn)
160+
conn.validate_session(operation.client, operation.session) # type: ignore[arg-type]
161161
more_to_come = bool(operation.conn_mgr and operation.conn_mgr.more_to_come)
162-
cmd, dbn = await self.operation_to_command(operation, conn, use_cmd)
162+
cmd, dbn = await self.operation_to_command(operation, conn, True)
163163
if more_to_come:
164164
request_id = 0
165165
data = b""
166166
max_doc_size = 0
167167
else:
168-
message = operation.get_message(read_preference, conn, use_cmd)
168+
message = operation.get_message(read_preference, conn)
169169
request_id, data, max_doc_size = self._split_message(message)
170170

171-
user_fields = _CURSOR_DOC_FIELDS if use_cmd else None
171+
user_fields = _CURSOR_DOC_FIELDS
172172

173173
docs, reply, duration = await run_cursor_command(
174174
conn,
@@ -211,7 +211,6 @@ async def run_operation(
211211
conn=conn,
212212
duration=duration,
213213
request_id=request_id,
214-
from_command=use_cmd,
215214
docs=docs, # type: ignore[arg-type]
216215
more_to_come=more_to_come,
217216
)
@@ -221,7 +220,6 @@ async def run_operation(
221220
address=self._description.address,
222221
duration=duration,
223222
request_id=request_id,
224-
from_command=use_cmd,
225223
docs=docs, # type: ignore[arg-type]
226224
)
227225

0 commit comments

Comments
 (0)