Skip to content

Commit 3feed33

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver into PYTHON-5413
2 parents a1965e5 + e2bfa9a commit 3feed33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+333
-1449
lines changed

.evergreen/generated_configs/tasks.yml

Lines changed: 234 additions & 408 deletions
Large diffs are not rendered by default.

.evergreen/generated_configs/variants.yml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ buildvariants:
146146
COMPRESSOR: zlib
147147
- name: compression-zstd-rhel8
148148
tasks:
149-
- name: .test-standard !.server-4.0
149+
- name: .test-standard !.server-4.2
150150
display_name: Compression zstd RHEL8
151151
run_on:
152152
- rhel87-small
@@ -522,13 +522,6 @@ buildvariants:
522522
PYTHON_BINARY: /opt/python/3.9/bin/python3
523523

524524
# Server version tests
525-
- name: mongodb-v4.0
526-
tasks:
527-
- name: .server-version
528-
display_name: "* MongoDB v4.0"
529-
run_on:
530-
- rhel87-small
531-
tags: [coverage_tag]
532525
- name: mongodb-v4.2
533526
tasks:
534527
- name: .server-version
@@ -664,11 +657,3 @@ buildvariants:
664657
- rhel87-small
665658
expansions:
666659
STORAGE_ENGINE: inmemory
667-
- name: storage-mmapv1-rhel8
668-
tasks:
669-
- name: .test-standard !.sharded_cluster-auth-ssl .server-4.0
670-
display_name: Storage MMAPv1 RHEL8
671-
run_on:
672-
- rhel87-small
673-
expansions:
674-
STORAGE_ENGINE: mmapv1

.evergreen/scripts/generate_config.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
get_task_name,
2626
get_variant_name,
2727
get_versions_from,
28-
get_versions_until,
2928
handle_c_ext,
3029
write_functions_to_file,
3130
write_tasks_to_file,
@@ -196,7 +195,7 @@ def create_compression_variants():
196195
for compressor in "snappy", "zlib", "zstd":
197196
expansions = dict(COMPRESSOR=compressor)
198197
if compressor == "zstd":
199-
tasks = [".test-standard !.server-4.0"]
198+
tasks = [".test-standard !.server-4.2"]
200199
else:
201200
tasks = [".test-standard"]
202201
display_name = get_variant_name(f"Compression {compressor}", host)
@@ -249,16 +248,11 @@ def create_pyopenssl_variants():
249248

250249
def create_storage_engine_variants():
251250
host = DEFAULT_HOST
252-
engines = ["InMemory", "MMAPv1"]
251+
engines = ["InMemory"]
253252
variants = []
254253
for engine in engines:
255254
expansions = dict(STORAGE_ENGINE=engine.lower())
256-
if engine == engines[0]:
257-
tasks = [".test-standard .standalone-noauth-nossl"]
258-
else:
259-
# MongoDB 4.2 drops support for MMAPv1
260-
versions = get_versions_until("4.0")
261-
tasks = [f".test-standard !.sharded_cluster-auth-ssl .server-{v}" for v in versions]
255+
tasks = [".test-standard .standalone-noauth-nossl"]
262256
display_name = get_variant_name(f"Storage {engine}", host)
263257
variant = create_variant(tasks, display_name, host=host, expansions=expansions)
264258
variants.append(variant)

.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.0", "4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "rapid", "latest"]
24+
ALL_VERSIONS = ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "rapid", "latest"]
2525
CPYTHONS = ["3.9", "3.10", "3.11", "3.12", "3.13"]
2626
PYPYS = ["pypy3.10"]
2727
ALL_PYTHONS = CPYTHONS + PYPYS

bson/binary.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ def as_vector(self) -> BinaryVector:
490490
dtype = BinaryVectorDtype(dtype)
491491
n_values = len(self) - position
492492

493+
if padding and dtype != BinaryVectorDtype.PACKED_BIT:
494+
raise ValueError(
495+
f"Corrupt data. Padding ({padding}) must be 0 for all but PACKED_BIT dtypes. ({dtype=})"
496+
)
497+
493498
if dtype == BinaryVectorDtype.INT8:
494499
dtype_format = "b"
495500
format_string = f"<{n_values}{dtype_format}"
@@ -510,6 +515,10 @@ def as_vector(self) -> BinaryVector:
510515

511516
elif dtype == BinaryVectorDtype.PACKED_BIT:
512517
# data packed as uint8
518+
if padding and not n_values:
519+
raise ValueError("Corrupt data. Vector has a padding P, but no data.")
520+
if padding > 7 or padding < 0:
521+
raise ValueError(f"Corrupt data. Padding ({padding}) must be between 0 and 7.")
513522
dtype_format = "B"
514523
format_string = f"<{n_values}{dtype_format}"
515524
unpacked_uint8s = list(struct.unpack_from(format_string, self, position))

doc/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ PyMongo 4.14 brings a number of changes including:
88
- Added :attr:`bson.codec_options.TypeRegistry.codecs` and :attr:`bson.codec_options.TypeRegistry.fallback_encoder` properties
99
to allow users to directly access the type codecs and fallback encoder for a given :class:`bson.codec_options.TypeRegistry`.
1010

11+
- Introduces a minor breaking change. When encoding :class:`bson.binary.BinaryVector`, a ``ValueError`` will be raised
12+
if the 'padding' metadata field is < 0 or > 7, or non-zero for any type other than PACKED_BIT.
13+
1114
Changes in Version 4.13.2 (2025/06/17)
1215
--------------------------------------
1316

pymongo/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
MAX_WRITE_BATCH_SIZE = 100000
6767

6868
# What this version of PyMongo supports.
69-
MIN_SUPPORTED_SERVER_VERSION = "4.0"
70-
MIN_SUPPORTED_WIRE_VERSION = 7
69+
MIN_SUPPORTED_SERVER_VERSION = "4.2"
70+
MIN_SUPPORTED_WIRE_VERSION = 8
7171
# MongoDB 8.0
7272
MAX_SUPPORTED_WIRE_VERSION = 25
7373

test/__init__.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -509,19 +509,6 @@ def require_data_lake(self, func):
509509
func=func,
510510
)
511511

512-
def require_no_mmap(self, func):
513-
"""Run a test only if the server is not using the MMAPv1 storage
514-
engine. Only works for standalone and replica sets; tests are
515-
run regardless of storage engine on sharded clusters.
516-
"""
517-
518-
def is_not_mmap():
519-
if self.is_mongos:
520-
return True
521-
return self.storage_engine != "mmapv1"
522-
523-
return self._require(is_not_mmap, "Storage engine must not be MMAPv1", func=func)
524-
525512
def require_version_min(self, *ver):
526513
"""Run a test only if the server version is at least ``version``."""
527514
other_version = Version(*ver)
@@ -652,7 +639,7 @@ def require_no_load_balancer(self, func):
652639

653640
def require_change_streams(self, func):
654641
"""Run a test only if the server supports change streams."""
655-
return self.require_no_mmap(self.require_no_standalone(func))
642+
return self.require_no_standalone(func)
656643

657644
def is_topology_type(self, topologies):
658645
unknown = set(topologies) - {
@@ -755,8 +742,6 @@ def require_sessions(self, func):
755742
return self._require(lambda: self.sessions_enabled, "Sessions not supported", func=func)
756743

757744
def supports_retryable_writes(self):
758-
if self.storage_engine == "mmapv1":
759-
return False
760745
if not self.sessions_enabled:
761746
return False
762747
return self.is_mongos or self.is_rs
@@ -770,9 +755,6 @@ def require_retryable_writes(self, func):
770755
)
771756

772757
def supports_transactions(self):
773-
if self.storage_engine == "mmapv1":
774-
return False
775-
776758
if self.version.at_least(4, 1, 8):
777759
return self.is_mongos or self.is_rs
778760

test/asynchronous/__init__.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -509,19 +509,6 @@ def require_data_lake(self, func):
509509
func=func,
510510
)
511511

512-
def require_no_mmap(self, func):
513-
"""Run a test only if the server is not using the MMAPv1 storage
514-
engine. Only works for standalone and replica sets; tests are
515-
run regardless of storage engine on sharded clusters.
516-
"""
517-
518-
def is_not_mmap():
519-
if self.is_mongos:
520-
return True
521-
return self.storage_engine != "mmapv1"
522-
523-
return self._require(is_not_mmap, "Storage engine must not be MMAPv1", func=func)
524-
525512
def require_version_min(self, *ver):
526513
"""Run a test only if the server version is at least ``version``."""
527514
other_version = Version(*ver)
@@ -652,7 +639,7 @@ def require_no_load_balancer(self, func):
652639

653640
def require_change_streams(self, func):
654641
"""Run a test only if the server supports change streams."""
655-
return self.require_no_mmap(self.require_no_standalone(func))
642+
return self.require_no_standalone(func)
656643

657644
async def is_topology_type(self, topologies):
658645
unknown = set(topologies) - {
@@ -755,8 +742,6 @@ def require_sessions(self, func):
755742
return self._require(lambda: self.sessions_enabled, "Sessions not supported", func=func)
756743

757744
def supports_retryable_writes(self):
758-
if self.storage_engine == "mmapv1":
759-
return False
760745
if not self.sessions_enabled:
761746
return False
762747
return self.is_mongos or self.is_rs
@@ -770,9 +755,6 @@ def require_retryable_writes(self, func):
770755
)
771756

772757
def supports_transactions(self):
773-
if self.storage_engine == "mmapv1":
774-
return False
775-
776758
if self.version.at_least(4, 1, 8):
777759
return self.is_mongos or self.is_rs
778760

test/asynchronous/test_bulk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ async def _test_update_many(self, update):
165165
async def test_update_many(self):
166166
await self._test_update_many({"$set": {"foo": "bar"}})
167167

168-
@async_client_context.require_version_min(4, 1, 11)
168+
@async_client_context.require_version_min(4, 2, 0)
169169
async def test_update_many_pipeline(self):
170170
await self._test_update_many([{"$set": {"foo": "bar"}}])
171171

@@ -206,7 +206,7 @@ async def _test_update_one(self, update):
206206
async def test_update_one(self):
207207
await self._test_update_one({"$set": {"foo": "bar"}})
208208

209-
@async_client_context.require_version_min(4, 1, 11)
209+
@async_client_context.require_version_min(4, 2, 0)
210210
async def test_update_one_pipeline(self):
211211
await self._test_update_one([{"$set": {"foo": "bar"}}])
212212

0 commit comments

Comments
 (0)