Skip to content

Commit 50c037a

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver
2 parents cb14e33 + ad88879 commit 50c037a

File tree

48 files changed

+780
-68
lines changed

Some content is hidden

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

48 files changed

+780
-68
lines changed

doc/changelog.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ PyMongo 4.9 brings a number of improvements including:
88

99
- Added support for MongoDB 8.0.
1010
- A new asynchronous API with full asyncio support.
11-
- Add support for :attr:`~pymongo.encryption.Algorithm.RANGE` and deprecate
12-
:attr:`~pymongo.encryption.Algorithm.RANGEPREVIEW`.
11+
- Added support for In-Use Encryption range queries with MongoDB 8.0.
12+
Added :attr:`~pymongo.encryption.Algorithm.RANGE`.
13+
``sparsity`` and ``trim_factor`` are now optional in :class:`~pymongo.encryption_options.RangeOpts`.
1314
- pymongocrypt>=1.10 is now required for :ref:`In-Use Encryption` support.
1415
- Added :meth:`~pymongo.cursor.Cursor.to_list` to :class:`~pymongo.cursor.Cursor`,
1516
:class:`~pymongo.command_cursor.CommandCursor`,

pymongo/encryption_options.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ class RangeOpts:
238238

239239
def __init__(
240240
self,
241-
sparsity: int,
242-
trim_factor: int,
241+
sparsity: Optional[int] = None,
242+
trim_factor: Optional[int] = None,
243243
min: Optional[Any] = None,
244244
max: Optional[Any] = None,
245245
precision: Optional[int] = None,
@@ -264,7 +264,7 @@ def __init__(
264264
def document(self) -> dict[str, Any]:
265265
doc = {}
266266
for k, v in [
267-
("sparsity", int64.Int64(self.sparsity)),
267+
("sparsity", int64.Int64(self.sparsity) if self.sparsity else None),
268268
("trimFactor", self.trim_factor),
269269
("precision", self.precision),
270270
("min", self.min),

pymongo/message.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,8 @@ def _check_doc_size_limits(
11231123
new_message_size = total_ops_length + total_ns_length + op_length + ns_length
11241124
# We have enough data, return this batch.
11251125
if new_message_size > max_doc_sequences_bytes:
1126+
if idx == 0:
1127+
_raise_document_too_large(op_type, op_length, max_bson_size + _COMMAND_OVERHEAD)
11261128
break
11271129

11281130
# Add op and ns documents to this batch.

test/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@
7979

8080
_IS_SYNC = True
8181

82-
# The default asyncio loop implementation on Windows
83-
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
84-
# We explicitly use a different loop implementation here to prevent that issue
85-
if (
86-
not _IS_SYNC
87-
and sys.platform == "win32"
88-
and asyncio.get_event_loop_policy() == asyncio.WindowsProactorEventLoopPolicy
89-
):
90-
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined]
91-
9282

9383
class ClientContext:
9484
client: MongoClient

test/asynchronous/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@
7979

8080
_IS_SYNC = False
8181

82-
# The default asyncio loop implementation on Windows
83-
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
84-
# We explicitly use a different loop implementation here to prevent that issue
85-
if (
86-
not _IS_SYNC
87-
and sys.platform == "win32"
88-
and asyncio.get_event_loop_policy() == asyncio.WindowsProactorEventLoopPolicy
89-
):
90-
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined]
91-
9282

9383
class AsyncClientContext:
9484
client: AsyncMongoClient

test/asynchronous/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
from __future__ import annotations
22

3+
import asyncio
4+
import sys
35
from test import pytest_conf
46
from test.asynchronous import async_setup, async_teardown
57

8+
import pytest
69
import pytest_asyncio
710

811
_IS_SYNC = False
912

1013

14+
@pytest.fixture(scope="session")
15+
def event_loop_policy():
16+
# The default asyncio loop implementation on Windows
17+
# has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240)
18+
# We explicitly use a different loop implementation here to prevent that issue
19+
if sys.platform == "win32":
20+
return asyncio.WindowsSelectorEventLoopPolicy() # type: ignore[attr-defined]
21+
22+
return asyncio.get_event_loop_policy()
23+
24+
1125
@pytest_asyncio.fixture(scope="session", autouse=True)
1226
async def test_setup_and_teardown():
1327
await async_setup()

test/asynchronous/test_client_bulk_write.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,15 @@ async def test_returns_error_if_no_writes_can_be_added_to_ops(self):
512512
# Document too large.
513513
b_repeated = "b" * self.max_message_size_bytes
514514
models = [InsertOne(namespace="db.coll", document={"a": b_repeated})]
515-
with self.assertRaises(InvalidOperation) as context:
515+
with self.assertRaises(DocumentTooLarge):
516516
await client.bulk_write(models=models)
517-
self.assertIn("cannot do an empty bulk write", context.exception._message)
518517

519518
# Namespace too large.
520519
c_repeated = "c" * self.max_message_size_bytes
521520
namespace = f"db.{c_repeated}"
522521
models = [InsertOne(namespace=namespace, document={"a": "b"})]
523-
with self.assertRaises(InvalidOperation) as context:
522+
with self.assertRaises(DocumentTooLarge):
524523
await client.bulk_write(models=models)
525-
self.assertIn("cannot do an empty bulk write", context.exception._message)
526524

527525
@async_client_context.require_version_min(8, 0, 0, -24)
528526
@unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed")

test/client-side-encryption/spec/legacy/fle2v2-Compact.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@
130130
"command": {
131131
"compactStructuredEncryptionData": "default"
132132
}
133+
},
134+
"result": {
135+
"ok": 1
133136
}
134137
}
135138
],

0 commit comments

Comments
 (0)