Skip to content

Commit 504d2b1

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver into PYTHON-3460
2 parents b431cdc + 14e8b01 commit 504d2b1

File tree

97 files changed

+1354
-2506
lines changed

Some content is hidden

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

97 files changed

+1354
-2506
lines changed

.evergreen/utils.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ createvirtualenv () {
3030
fi
3131

3232
python -m pip install --upgrade pip
33-
python -m pip install --upgrade setuptools wheel unittest-xml-reporting
33+
python -m pip install --upgrade setuptools wheel
34+
# lxml only has wheels for macos 10.15+
35+
python -m pip install unittest-xml-reporting || true
36+
3437
}
3538

3639
# Usage:

.github/workflows/test-python.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,14 @@ jobs:
5858
cache-dependency-path: 'setup.py'
5959
- name: Install dependencies
6060
run: |
61-
python -m pip install -U pip mypy==0.990
61+
python -m pip install -U pip mypy==1.2
6262
pip install -e ".[zstd, encryption, ocsp]"
6363
- name: Run mypy
6464
run: |
6565
mypy --install-types --non-interactive bson gridfs tools pymongo
66-
# Test overshadowed codec_options.py file
67-
mypy --install-types --non-interactive bson/codec_options.py
6866
mypy --install-types --non-interactive --disable-error-code var-annotated --disable-error-code attr-defined --disable-error-code union-attr --disable-error-code assignment --disable-error-code no-redef --disable-error-code index --allow-redefinition --allow-untyped-globals --exclude "test/mypy_fails/*.*" test
6967
python -m pip install -U typing_extensions
7068
mypy --install-types --non-interactive test/test_typing.py test/test_typing_strict.py
71-
- name: Run mypy strict
72-
run: |
73-
mypy --strict test/test_typing_strict.py
7469
- name: Run pyright
7570
run: |
7671
python -m pip install -U pip pyright==1.1.290

bson/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ def decode_all(
11151115
if not isinstance(opts, CodecOptions):
11161116
raise _CODEC_OPTIONS_TYPE_ERROR
11171117

1118-
return _decode_all(data, opts) # type: ignore[arg-type]
1118+
return _decode_all(data, opts) # type:ignore[arg-type]
11191119

11201120

11211121
def _decode_selective(rawdoc: Any, fields: Any, codec_options: Any) -> Mapping[Any, Any]:

bson/codec_options.py

Lines changed: 253 additions & 205 deletions
Large diffs are not rendered by default.

bson/codec_options.pyi

Lines changed: 0 additions & 106 deletions
This file was deleted.

bson/decimal128.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _decimal_to_128(value: _VALUE_OPTIONS) -> Tuple[int, int]:
100100
if significand & (1 << i):
101101
high |= 1 << (i - 64)
102102

103-
biased_exponent = exponent + _EXPONENT_BIAS
103+
biased_exponent = exponent + _EXPONENT_BIAS # type: ignore[operator]
104104

105105
if high >> 49 == 1:
106106
high = high & 0x7FFFFFFFFFFF

bson/son.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(
6666
self.update(kwargs)
6767

6868
def __new__(cls: Type["SON[_Key, _Value]"], *args: Any, **kwargs: Any) -> "SON[_Key, _Value]":
69-
instance = super(SON, cls).__new__(cls, *args, **kwargs)
69+
instance = super(SON, cls).__new__(cls, *args, **kwargs) # type: ignore[type-var]
7070
instance.__keys = []
7171
return instance
7272

@@ -115,7 +115,7 @@ def clear(self) -> None:
115115
self.__keys = []
116116
super(SON, self).clear()
117117

118-
def setdefault(self, key: _Key, default: _Value) -> _Value: # type: ignore[override]
118+
def setdefault(self, key: _Key, default: _Value) -> _Value:
119119
try:
120120
return self[key]
121121
except KeyError:

doc/changelog.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ Changes in Version 4.4
88
or keys to :meth:`~pymongo.collection.Collection.create_index`.
99
- pymongocrypt 1.5.0 or later is now required for client side field level
1010
encryption support.
11-
- Improved support for Pyright to improve typing support for IDEs like Visual Studio Code or Visual Studio.
11+
- Improved support for Pyright to improve typing support for IDEs like Visual Studio Code
12+
or Visual Studio.
1213
- Improved support for type-checking with MyPy "strict" mode (`--strict`).
1314
- Added support for Python 3.11.
15+
- pymongocrypt 1.6.0 or later is now required for Client Side Field Level Encryption (CSFLE)
16+
and Queryable Encryption (QE) support. MongoDB Server 7.0 introduced a backwards breaking
17+
change to the QE protocol. Users taking advantage of the QE beta must now upgrade to
18+
MongoDB 7.0+ and PyMongo 4.4+.
1419

1520
Issues Resolved
1621
...............

doc/examples/encryption.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,13 @@ data key and create a collection with the
364364
Automatic Queryable Encryption (Beta)
365365
`````````````````````````````````````
366366

367-
PyMongo 4.2 brings beta support for Queryable Encryption with MongoDB >=6.0.
367+
PyMongo 4.4 brings beta support for Queryable Encryption with MongoDB >=7.0.
368368

369369
Queryable Encryption is the second version of Client-Side Field Level Encryption.
370370
Data is encrypted client-side. Queryable Encryption supports indexed encrypted fields,
371371
which are further processed server-side.
372372

373-
You must have MongoDB 6.0 Enterprise to preview the capability.
373+
You must have MongoDB 7.0 Enterprise to preview the capability.
374374

375375
Automatic encryption in Queryable Encryption is configured with an ``encrypted_fields`` mapping, as demonstrated by the following example::
376376

@@ -396,7 +396,6 @@ Automatic encryption in Queryable Encryption is configured with an ``encrypted_f
396396
encrypted_fields_map = {
397397
"default.encryptedCollection": {
398398
"escCollection": "encryptedCollection.esc",
399-
"eccCollection": "encryptedCollection.ecc",
400399
"ecocCollection": "encryptedCollection.ecoc",
401400
"fields": [
402401
{
@@ -429,7 +428,7 @@ automatically encrypted and decrypted.
429428
Explicit Queryable Encryption (Beta)
430429
````````````````````````````````````
431430

432-
PyMongo 4.2 brings beta support for Queryable Encryption with MongoDB >=6.0.
431+
PyMongo 4.4 brings beta support for Queryable Encryption with MongoDB >=7.0.
433432

434433
Queryable Encryption is the second version of Client-Side Field Level Encryption.
435434
Data is encrypted client-side. Queryable Encryption supports indexed encrypted fields,
@@ -487,7 +486,6 @@ using an ``encrypted_fields`` mapping, as demonstrated by the following example:
487486

488487
encrypted_fields = {
489488
"escCollection": "enxcol_.default.esc",
490-
"eccCollection": "enxcol_.default.ecc",
491489
"ecocCollection": "enxcol_.default.ecoc",
492490
"fields": [
493491
{

pymongo/collection.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from pymongo.change_stream import CollectionChangeStream
4444
from pymongo.collation import validate_collation_or_none
4545
from pymongo.command_cursor import CommandCursor, RawBatchCommandCursor
46-
from pymongo.common import _ecc_coll_name, _ecoc_coll_name, _esc_coll_name
46+
from pymongo.common import _ecoc_coll_name, _esc_coll_name
4747
from pymongo.cursor import Cursor, RawBatchCursor
4848
from pymongo.errors import (
4949
ConfigurationError,
@@ -232,8 +232,9 @@ def __init__(
232232
if encrypted_fields:
233233
common.validate_is_mapping("encrypted_fields", encrypted_fields)
234234
opts = {"clusteredIndex": {"key": {"_id": 1}, "unique": True}}
235-
self.__create(_esc_coll_name(encrypted_fields, name), opts, None, session)
236-
self.__create(_ecc_coll_name(encrypted_fields, name), opts, None, session)
235+
self.__create(
236+
_esc_coll_name(encrypted_fields, name), opts, None, session, qev2_required=True
237+
)
237238
self.__create(_ecoc_coll_name(encrypted_fields, name), opts, None, session)
238239
self.__create(name, kwargs, collation, session, encrypted_fields=encrypted_fields)
239240
self.create_index([("__safeContent__", ASCENDING)], session)
@@ -305,7 +306,9 @@ def _command(
305306
user_fields=user_fields,
306307
)
307308

308-
def __create(self, name, options, collation, session, encrypted_fields=None):
309+
def __create(
310+
self, name, options, collation, session, encrypted_fields=None, qev2_required=False
311+
):
309312
"""Sends a create command with the given options."""
310313
cmd = SON([("create", name)])
311314
if encrypted_fields:
@@ -316,6 +319,13 @@ def __create(self, name, options, collation, session, encrypted_fields=None):
316319
options["size"] = float(options["size"])
317320
cmd.update(options)
318321
with self._socket_for_writes(session) as sock_info:
322+
if qev2_required and sock_info.max_wire_version < 21:
323+
raise ConfigurationError(
324+
"Driver support of Queryable Encryption is incompatible with server. "
325+
"Upgrade server to use Queryable Encryption. "
326+
f"Got maxWireVersion {sock_info.max_wire_version} but need maxWireVersion >= 21 (MongoDB >=7.0)"
327+
)
328+
319329
self._command(
320330
sock_info,
321331
cmd,
@@ -2020,11 +2030,11 @@ def create_index(
20202030
pairs specifying the index to create
20212031
- `session` (optional): a
20222032
:class:`~pymongo.client_session.ClientSession`.
2023-
arguments
20242033
- `comment` (optional): A user-provided comment to attach to this
20252034
command.
20262035
- `**kwargs` (optional): any additional index creation
20272036
options (see the above list) should be passed as keyword
2037+
arguments.
20282038
20292039
.. versionchanged:: 4.4
20302040
Allow passing a list containing (key, direction) pairs
@@ -2072,14 +2082,11 @@ def drop_indexes(
20722082
:Parameters:
20732083
- `session` (optional): a
20742084
:class:`~pymongo.client_session.ClientSession`.
2075-
arguments
20762085
- `comment` (optional): A user-provided comment to attach to this
20772086
command.
20782087
- `**kwargs` (optional): optional arguments to the createIndexes
20792088
command (like maxTimeMS) can be passed as keyword arguments.
20802089
2081-
2082-
20832090
.. note:: The :attr:`~pymongo.collection.Collection.write_concern` of
20842091
this collection is automatically applied to this operation.
20852092
@@ -2090,7 +2097,6 @@ def drop_indexes(
20902097
.. versionchanged:: 3.4
20912098
Apply this collection's write concern automatically to this operation
20922099
when connected to MongoDB >= 3.4.
2093-
20942100
"""
20952101
if comment is not None:
20962102
kwargs["comment"] = comment

pymongo/common.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,6 @@ def _esc_coll_name(encrypted_fields, name):
859859
return encrypted_fields.get("escCollection", f"enxcol_.{name}.esc")
860860

861861

862-
def _ecc_coll_name(encrypted_fields, name):
863-
return encrypted_fields.get("eccCollection", f"enxcol_.{name}.ecc")
864-
865-
866862
def _ecoc_coll_name(encrypted_fields, name):
867863
return encrypted_fields.get("ecocCollection", f"enxcol_.{name}.ecoc")
868864

pymongo/database.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from pymongo.change_stream import DatabaseChangeStream
4040
from pymongo.collection import Collection
4141
from pymongo.command_cursor import CommandCursor
42-
from pymongo.common import _ecc_coll_name, _ecoc_coll_name, _esc_coll_name
42+
from pymongo.common import _ecoc_coll_name, _esc_coll_name
4343
from pymongo.errors import CollectionInvalid, InvalidName
4444
from pymongo.read_preferences import ReadPreference, _ServerMode
4545
from pymongo.typings import _CollationIn, _DocumentType, _DocumentTypeArg, _Pipeline
@@ -394,7 +394,6 @@ def create_collection(
394394
395395
{
396396
"escCollection": "enxcol_.encryptedCollection.esc",
397-
"eccCollection": "enxcol_.encryptedCollection.ecc",
398397
"ecocCollection": "enxcol_.encryptedCollection.ecoc",
399398
"fields": [
400399
{
@@ -1009,7 +1008,6 @@ def drop_collection(
10091008
10101009
{
10111010
"escCollection": "enxcol_.encryptedCollection.esc",
1012-
"eccCollection": "enxcol_.encryptedCollection.ecc",
10131011
"ecocCollection": "enxcol_.encryptedCollection.ecoc",
10141012
"fields": [
10151013
{
@@ -1061,9 +1059,6 @@ def drop_collection(
10611059
self._drop_helper(
10621060
_esc_coll_name(encrypted_fields, name), session=session, comment=comment
10631061
)
1064-
self._drop_helper(
1065-
_ecc_coll_name(encrypted_fields, name), session=session, comment=comment
1066-
)
10671062
self._drop_helper(
10681063
_ecoc_coll_name(encrypted_fields, name), session=session, comment=comment
10691064
)

0 commit comments

Comments
 (0)