From e37ac41aa35cb8c2ee99148f82e3dfb098521fce Mon Sep 17 00:00:00 2001 From: Jib Date: Thu, 1 Feb 2024 13:50:40 -0500 Subject: [PATCH 1/6] PYTHON-4183: Unavoidable breaking change with BSON --- doc/changelog.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index c5fd8758dd..ec4e3df370 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -11,8 +11,6 @@ PyMongo 4.7 brings a number of improvements including: :attr:`pymongo.monitoring.CommandSucceededEvent.server_connection_id`, and :attr:`pymongo.monitoring.CommandFailedEvent.server_connection_id` properties. - Fixed a bug where inflating a :class:`~bson.raw_bson.RawBSONDocument` containing a :class:`~bson.code.Code` would cause an error. -- Replaced usage of :class:`bson.son.SON` on all internal classes and commands to dict, - :attr:`options.pool_options.metadata` is now of type ``dict`` as opposed to :class:`bson.son.SON`. - Significantly improved the performance of encoding BSON documents to JSON. - Support for named KMS providers for client side field level encryption. Previously supported KMS providers were only: aws, azure, gcp, kmip, and local. @@ -29,6 +27,15 @@ PyMongo 4.7 brings a number of improvements including: .. _orjson: https://github.com/ijl/orjson +Unavoidable breaking changes +............................ + +- Replaced usage of :class:`bson.son.SON` on all internal classes and commands to dict, + :attr:`options.pool_options.metadata` is now of type ``dict`` as opposed to :class:`bson.son.SON`. + Here's an example of how this changes expected output:: + + >>> ... + Changes in Version 4.6.1 ------------------------ From fe2f7e0af1d6701f03ebe98d5557a0fcb055c7b0 Mon Sep 17 00:00:00 2001 From: Jib Date: Thu, 1 Feb 2024 16:28:59 -0500 Subject: [PATCH 2/6] provided examples in the changelog.rst --- doc/changelog.rst | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index ec4e3df370..ee17c5c4b4 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -34,7 +34,28 @@ Unavoidable breaking changes :attr:`options.pool_options.metadata` is now of type ``dict`` as opposed to :class:`bson.son.SON`. Here's an example of how this changes expected output:: - >>> ... + # Before + >>> client.options.pool_options.metadata + SON([('driver', SON([('name', 'PyMongo'), ('version', '4.7.0.dev0')])), ('os', SON([('type', 'Darwin'), ('name', 'Darwin'), ('architecture', 'arm64'), ('version', '14.3')])), ('platform', 'CPython 3.11.6.final.0')]) + + # After + >>> client.options.pool_options.metadata + {'driver': {'name': 'PyMongo', 'version': '4.7.0.dev0'}, 'os': {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}, 'platform': 'CPython 3.11.6.final.0'} + + # To convert from dict to SON + # This will only convert the first layer of the dictionary + >>> data_as_dict = client.options.pool_options.metadata + >>> SON(data_as_dict) + SON([('driver', {'name': 'PyMongo', 'version': '4.7.0.dev0'}), ('os', {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}), ('platform', 'CPython 3.11.6.final.0')]) + + # To convert from dict to SON on a nested dictionary + >>> def dict_to_SON(data_as_dict: dict[Any, Any]): + ... data_as_SON = SON() + ... for key, value in data_as_dict.items(): + ... data_as_SON[key] = dict_to_SON(value) if isinstance(value, dict) else value + ... return data_as_SON + >>> + >>> dict_to_SON(data_as_dict) Changes in Version 4.6.1 ------------------------ From cc9fbe7494a8768a8f47f3ba99b33b2b215a65ca Mon Sep 17 00:00:00 2001 From: Jib Date: Thu, 1 Feb 2024 16:34:10 -0500 Subject: [PATCH 3/6] included the expected output from the examples --- doc/changelog.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index ee17c5c4b4..479990d7f5 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -32,18 +32,25 @@ Unavoidable breaking changes - Replaced usage of :class:`bson.son.SON` on all internal classes and commands to dict, :attr:`options.pool_options.metadata` is now of type ``dict`` as opposed to :class:`bson.son.SON`. - Here's an example of how this changes expected output:: + Here's some examples of how this changes expected output as well as how to convert from :class:`dict` to :class:`bson.son.SON`:: # Before + >>> from pymongo import MongoClient + >>> client = MongoClient() >>> client.options.pool_options.metadata SON([('driver', SON([('name', 'PyMongo'), ('version', '4.7.0.dev0')])), ('os', SON([('type', 'Darwin'), ('name', 'Darwin'), ('architecture', 'arm64'), ('version', '14.3')])), ('platform', 'CPython 3.11.6.final.0')]) # After + >>> from pymongo import MongoClient + >>> client = MongoClient() >>> client.options.pool_options.metadata {'driver': {'name': 'PyMongo', 'version': '4.7.0.dev0'}, 'os': {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}, 'platform': 'CPython 3.11.6.final.0'} # To convert from dict to SON # This will only convert the first layer of the dictionary + >>> from pymongo import MongoClient + >>> from bson import SON + >>> client = MongoClient() >>> data_as_dict = client.options.pool_options.metadata >>> SON(data_as_dict) SON([('driver', {'name': 'PyMongo', 'version': '4.7.0.dev0'}), ('os', {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}), ('platform', 'CPython 3.11.6.final.0')]) @@ -56,6 +63,7 @@ Unavoidable breaking changes ... return data_as_SON >>> >>> dict_to_SON(data_as_dict) + SON([('driver', SON([('name', 'PyMongo'), ('version', '4.7.0.dev0')])), ('os', SON([('type', 'Darwin'), ('name', 'Darwin'), ('architecture', 'arm64'), ('version', '14.3')])), ('platform', 'CPython 3.11.6.final.0')]) Changes in Version 4.6.1 ------------------------ From a21066aab40de627e13f9f45aff13ca8eee4f430 Mon Sep 17 00:00:00 2001 From: Jib Date: Fri, 2 Feb 2024 10:23:45 -0500 Subject: [PATCH 4/6] removed redundant import statements --- doc/changelog.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 479990d7f5..7801343e65 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -41,16 +41,11 @@ Unavoidable breaking changes SON([('driver', SON([('name', 'PyMongo'), ('version', '4.7.0.dev0')])), ('os', SON([('type', 'Darwin'), ('name', 'Darwin'), ('architecture', 'arm64'), ('version', '14.3')])), ('platform', 'CPython 3.11.6.final.0')]) # After - >>> from pymongo import MongoClient - >>> client = MongoClient() >>> client.options.pool_options.metadata {'driver': {'name': 'PyMongo', 'version': '4.7.0.dev0'}, 'os': {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}, 'platform': 'CPython 3.11.6.final.0'} # To convert from dict to SON # This will only convert the first layer of the dictionary - >>> from pymongo import MongoClient - >>> from bson import SON - >>> client = MongoClient() >>> data_as_dict = client.options.pool_options.metadata >>> SON(data_as_dict) SON([('driver', {'name': 'PyMongo', 'version': '4.7.0.dev0'}), ('os', {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}), ('platform', 'CPython 3.11.6.final.0')]) From a0027e2d225674ab118f7c6eef1ed72108bbb3a3 Mon Sep 17 00:00:00 2001 From: Jib Date: Mon, 5 Feb 2024 08:49:17 -0500 Subject: [PATCH 5/6] additional whitespace --- doc/changelog.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 4699c148ca..baeaec074d 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -62,8 +62,6 @@ Unavoidable breaking changes >>> >>> dict_to_SON(data_as_dict) SON([('driver', SON([('name', 'PyMongo'), ('version', '4.7.0.dev0')])), ('os', SON([('type', 'Darwin'), ('name', 'Darwin'), ('architecture', 'arm64'), ('version', '14.3')])), ('platform', 'CPython 3.11.6.final.0')]) - - Changes in Version 4.6.1 ------------------------ From 54c00cd58553878d0b823171b4136db45b58b9ee Mon Sep 17 00:00:00 2001 From: Jib Date: Mon, 5 Feb 2024 08:50:29 -0500 Subject: [PATCH 6/6] Keep ONE additional whitespace --- doc/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changelog.rst b/doc/changelog.rst index baeaec074d..5cc96089de 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -62,6 +62,7 @@ Unavoidable breaking changes >>> >>> dict_to_SON(data_as_dict) SON([('driver', SON([('name', 'PyMongo'), ('version', '4.7.0.dev0')])), ('os', SON([('type', 'Darwin'), ('name', 'Darwin'), ('architecture', 'arm64'), ('version', '14.3')])), ('platform', 'CPython 3.11.6.final.0')]) + Changes in Version 4.6.1 ------------------------