From 3ef53d142d9f6c627012e090e9205526a99e9b37 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Mon, 29 Nov 2021 10:25:34 -0800 Subject: [PATCH 01/12] BUMP 3.12.3.dev0 --- pymongo/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pymongo/__init__.py b/pymongo/__init__.py index 3e105f7ce1..a5aef43fd4 100644 --- a/pymongo/__init__.py +++ b/pymongo/__init__.py @@ -99,7 +99,7 @@ Deprecated """ -version_tuple = (3, 12, 2) +version_tuple = (3, 12, 3, '.dev0') def get_version_string(): if isinstance(version_tuple[-1], str): diff --git a/setup.py b/setup.py index bcff20231a..539e63af87 100755 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ except ImportError: _HAVE_SPHINX = False -version = "3.12.2" +version = "3.12.3.dev0" f = open("README.rst") try: From f7d757dd01fafc7d7f5137803b93a45ca3746a57 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Mon, 6 Dec 2021 11:26:36 -0800 Subject: [PATCH 02/12] PYTHON-3033 Fix typo in uuid docs (#808) (cherry picked from commit 44853ea9c3ffe9dba5e356687f0870a1a41f3d7c) --- doc/examples/uuid.rst | 3 ++- pymongo/mongo_client.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/examples/uuid.rst b/doc/examples/uuid.rst index 4d55fbeae2..4ed504c99c 100644 --- a/doc/examples/uuid.rst +++ b/doc/examples/uuid.rst @@ -1,3 +1,4 @@ + .. _handling-uuid-data-example: Handling UUID Data @@ -12,7 +13,7 @@ to MongoDB and retrieve them as native :class:`uuid.UUID` objects:: from uuid import uuid4 # use the 'standard' representation for cross-language compatibility. - client = MongoClient(uuid_representation=UuidRepresentation.STANDARD) + client = MongoClient(uuidRepresentation='standard') collection = client.get_database('uuid_db').get_collection('uuid_coll') # remove all documents from collection diff --git a/pymongo/mongo_client.py b/pymongo/mongo_client.py index 6b7f98380f..184ebf9eb7 100644 --- a/pymongo/mongo_client.py +++ b/pymongo/mongo_client.py @@ -342,9 +342,9 @@ def __init__( speed. 9 is best compression. Defaults to -1. - `uuidRepresentation`: The BSON representation to use when encoding from and decoding to instances of :class:`~uuid.UUID`. Valid - values are `pythonLegacy` (the default), `javaLegacy`, - `csharpLegacy`, `standard` and `unspecified`. New applications - should consider setting this to `standard` for cross language + values are the strings: "pythonLegacy" (the default), "javaLegacy", + "csharpLegacy", "standard" and "unspecified". New applications + should consider setting this to "standard" for cross language compatibility. See :ref:`handling-uuid-data-example` for details. - `unicode_decode_error_handler`: The error handler to apply when a Unicode-related error occurs during BSON decoding that would From 55091f1b79e8221763b9ab27e252377055f64bff Mon Sep 17 00:00:00 2001 From: Julius Park Date: Mon, 6 Dec 2021 13:13:15 -0800 Subject: [PATCH 03/12] PYTHON-3028 $regex as a field name does not allow for non-string values (#807) (cherry picked from commit 70f7fe75426b76debfce787a0ee2eb398c27a1ce) --- bson/json_util.py | 2 +- test/test_json_util.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bson/json_util.py b/bson/json_util.py index 38c39a12c8..03dabad893 100644 --- a/bson/json_util.py +++ b/bson/json_util.py @@ -505,7 +505,7 @@ def object_hook(dct, json_options=DEFAULT_JSON_OPTIONS): def _parse_legacy_regex(doc): pattern = doc["$regex"] # Check if this is the $regex query operator. - if isinstance(pattern, Regex): + if not isinstance(pattern, (text_type, bytes)): return doc flags = 0 # PyMongo always adds $options but some other tools may not. diff --git a/test/test_json_util.py b/test/test_json_util.py index 7906b276f5..3716915bc4 100644 --- a/test/test_json_util.py +++ b/test/test_json_util.py @@ -262,6 +262,15 @@ def test_regex(self): '{"$regex": ".*", "$options": "mx"}', json_util.dumps(re.compile(b'.*', re.M | re.X))) + def test_regex_validation(self): + non_str_types = [10, {}, []] + docs = [{"$regex": i} for i in non_str_types] + for doc in docs: + self.assertEqual(doc, json_util.loads(json.dumps(doc))) + + doc = {"$regex": ""} + self.assertIsInstance(json_util.loads(json.dumps(doc)), Regex) + def test_minkey(self): self.round_trip({"m": MinKey()}) From 0fe4ba7f0ba6389d9083b56bc43d57d4ee095f32 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Tue, 7 Dec 2021 11:42:48 -0800 Subject: [PATCH 04/12] BUMP 3.12.3 (#810) --- doc/changelog.rst | 15 +++++++++++++++ pymongo/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 5b89aafb90..92c54ae1f5 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,21 @@ Changelog ========= +Changes in Version 3.12.3 +------------------------- + +Issues Resolved +............... + +Version 3.12.3 fixes a bug that prevented :meth:`bson.json_util.loads` from +decoding a document with a non-string "$regex" field (`PYTHON-3028`_). + +See the `PyMongo 3.12.3 release notes in JIRA`_ for the list of resolved issues +in this release. + +.. _PYTHON-3028: https://jira.mongodb.org/browse/PYTHON-3028 +.. _PyMongo 3.12.3 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=32505 + Changes in Version 3.12.2 ------------------------- diff --git a/pymongo/__init__.py b/pymongo/__init__.py index a5aef43fd4..406984e824 100644 --- a/pymongo/__init__.py +++ b/pymongo/__init__.py @@ -99,7 +99,7 @@ Deprecated """ -version_tuple = (3, 12, 3, '.dev0') +version_tuple = (3, 12, 3) def get_version_string(): if isinstance(version_tuple[-1], str): diff --git a/setup.py b/setup.py index 539e63af87..b1715f31e9 100755 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ except ImportError: _HAVE_SPHINX = False -version = "3.12.3.dev0" +version = "3.12.3" f = open("README.rst") try: From 14329acee4a70be26e296d41449f4b77a889405e Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Tue, 7 Dec 2021 11:44:32 -0800 Subject: [PATCH 05/12] BUMP 3.12.4.dev0 --- pymongo/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pymongo/__init__.py b/pymongo/__init__.py index 406984e824..46e2081d59 100644 --- a/pymongo/__init__.py +++ b/pymongo/__init__.py @@ -99,7 +99,7 @@ Deprecated """ -version_tuple = (3, 12, 3) +version_tuple = (3, 12, 4, '.dev0') def get_version_string(): if isinstance(version_tuple[-1], str): diff --git a/setup.py b/setup.py index b1715f31e9..5248176f84 100755 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ except ImportError: _HAVE_SPHINX = False -version = "3.12.3" +version = "3.12.4.dev0" f = open("README.rst") try: From 584ad4d364da1be998c9dfba644222923314b36f Mon Sep 17 00:00:00 2001 From: Julius Park Date: Mon, 14 Feb 2022 11:26:14 -0800 Subject: [PATCH 06/12] PYTHON-3088 Update load balancer tests to support dedicated load balancer port (#866) (cherry picked from commit 341d489f38ad51620fab50bfc7c3f8c1227fefee) --- .evergreen/config.yml | 6 ++++++ pymongo/pool.py | 10 +--------- test/__init__.py | 11 ++++------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index ae6230408e..bd870b1a70 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -291,6 +291,7 @@ functions: DISABLE_TEST_COMMANDS=${DISABLE_TEST_COMMANDS} \ ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \ REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \ + LOAD_BALANCER=${LOAD_BALANCER} \ bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh # run-orchestration generates expansion file with the MONGODB_URI for the cluster - command: expansions.update @@ -423,6 +424,7 @@ functions: fi if [ -n "${test_loadbalancer}" ]; then export TEST_LOADBALANCER=1 + export LOAD_BALANCER=1 export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}" export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" fi @@ -1770,8 +1772,12 @@ tasks: commands: - func: "bootstrap mongo-orchestration" vars: + VERSION: "latest" TOPOLOGY: "sharded_cluster" + LOAD_BALANCER: true - func: "run load-balancer" + vars: + LOAD_BALANCER: true - func: "run tests" # }}} - name: "coverage-report" diff --git a/pymongo/pool.py b/pymongo/pool.py index 106c3a7a13..e1885b08fb 100644 --- a/pymongo/pool.py +++ b/pymongo/pool.py @@ -220,9 +220,6 @@ def _set_keepalive_times(sock): # main thread, to avoid the deadlock. See PYTHON-607. u'foo'.encode('idna') -# Remove after PYTHON-2712 -_MOCK_SERVICE_ID = False - def _raise_connection_failure(address, error, msg_prefix=None): """Convert a socket.error to ConnectionFailure and raise it.""" @@ -584,12 +581,7 @@ def _hello(self, cluster_time, topology_version, if auth_ctx: cmd['speculativeAuthenticate'] = auth_ctx.speculate_command() - doc = self.command('admin', cmd, publish_events=False, - exhaust_allowed=awaitable) - # PYTHON-2712 will remove this topologyVersion fallback logic. - if self.opts.load_balanced and _MOCK_SERVICE_ID: - process_id = doc.get('topologyVersion', {}).get('processId') - doc.setdefault('serviceId', process_id) + doc = self.command("admin", cmd, publish_events=False, exhaust_allowed=awaitable) if not self.opts.load_balanced: doc.pop('serviceId', None) hello = IsMaster(doc, awaitable=awaitable) diff --git a/test/__init__.py b/test/__init__.py index 87d27cf444..66891dfcc4 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -99,13 +99,10 @@ SINGLE_MONGOS_LB_URI = os.environ.get("SINGLE_MONGOS_LB_URI") MULTI_MONGOS_LB_URI = os.environ.get("MULTI_MONGOS_LB_URI") if TEST_LOADBALANCER: - # Remove after PYTHON-2712 - from pymongo import pool - pool._MOCK_SERVICE_ID = True - res = parse_uri(SINGLE_MONGOS_LB_URI) - host, port = res['nodelist'][0] - db_user = res['username'] or db_user - db_pwd = res['password'] or db_pwd + res = parse_uri(SINGLE_MONGOS_LB_URI or "") + host, port = res["nodelist"][0] + db_user = res["username"] or db_user + db_pwd = res["password"] or db_pwd elif TEST_SERVERLESS: TEST_LOADBALANCER = True res = parse_uri(SINGLE_MONGOS_LB_URI) From b9f8972eeb5a24b4b131031b7111ebbf878cd72c Mon Sep 17 00:00:00 2001 From: julius Date: Wed, 16 Feb 2022 13:44:08 -0800 Subject: [PATCH 07/12] fix config.yml and fix stray occurences of popping serviceid --- .evergreen/config.yml | 3 +-- pymongo/pool.py | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index bd870b1a70..dfdc4f281b 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -1772,7 +1772,6 @@ tasks: commands: - func: "bootstrap mongo-orchestration" vars: - VERSION: "latest" TOPOLOGY: "sharded_cluster" LOAD_BALANCER: true - func: "run load-balancer" @@ -2977,7 +2976,7 @@ buildvariants: - matrix_name: "load-balancer" matrix_spec: platform: awslinux - mongodb-version: ["5.0", "latest"] + mongodb-version: ["rapid", "latest"] auth-ssl: "*" python-version: ["2.7", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "pypy", "pypy3.5", "pypy3.7"] loadbalancer: "*" diff --git a/pymongo/pool.py b/pymongo/pool.py index e1885b08fb..ea133e1433 100644 --- a/pymongo/pool.py +++ b/pymongo/pool.py @@ -582,8 +582,6 @@ def _hello(self, cluster_time, topology_version, cmd['speculativeAuthenticate'] = auth_ctx.speculate_command() doc = self.command("admin", cmd, publish_events=False, exhaust_allowed=awaitable) - if not self.opts.load_balanced: - doc.pop('serviceId', None) hello = IsMaster(doc, awaitable=awaitable) self.is_writable = hello.is_writable self.max_wire_version = hello.max_wire_version @@ -621,9 +619,6 @@ def _next_reply(self): unpacked_docs = reply.unpack_response() response_doc = unpacked_docs[0] helpers._check_command_response(response_doc, self.max_wire_version) - # Remove after PYTHON-2712. - if not self.opts.load_balanced: - response_doc.pop('serviceId', None) return response_doc def command(self, dbname, spec, secondary_ok=False, From 6a518b9228a04ab0ac1b2a67caef83efc1d11ce2 Mon Sep 17 00:00:00 2001 From: julius Date: Wed, 16 Feb 2022 14:01:02 -0800 Subject: [PATCH 08/12] cleanup merge --- doc/changelog.rst | 15 --------------- test/test_json_util.py | 9 --------- 2 files changed, 24 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 92c54ae1f5..5b89aafb90 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,21 +1,6 @@ Changelog ========= -Changes in Version 3.12.3 -------------------------- - -Issues Resolved -............... - -Version 3.12.3 fixes a bug that prevented :meth:`bson.json_util.loads` from -decoding a document with a non-string "$regex" field (`PYTHON-3028`_). - -See the `PyMongo 3.12.3 release notes in JIRA`_ for the list of resolved issues -in this release. - -.. _PYTHON-3028: https://jira.mongodb.org/browse/PYTHON-3028 -.. _PyMongo 3.12.3 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=32505 - Changes in Version 3.12.2 ------------------------- diff --git a/test/test_json_util.py b/test/test_json_util.py index d50df22c01..920700704b 100644 --- a/test/test_json_util.py +++ b/test/test_json_util.py @@ -274,15 +274,6 @@ def test_regex_validation(self): doc = {"$regex": ""} self.assertIsInstance(json_util.loads(json.dumps(doc)), Regex) - def test_regex_validation(self): - non_str_types = [10, {}, []] - docs = [{"$regex": i} for i in non_str_types] - for doc in docs: - self.assertEqual(doc, json_util.loads(json.dumps(doc))) - - doc = {"$regex": ""} - self.assertIsInstance(json_util.loads(json.dumps(doc)), Regex) - def test_minkey(self): self.round_trip({"m": MinKey()}) From 7927e521d426e31404b35d86b458d0ebfb0b4e2d Mon Sep 17 00:00:00 2001 From: julius Date: Wed, 16 Feb 2022 14:01:41 -0800 Subject: [PATCH 09/12] fix deleted newline --- pymongo/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pymongo/__init__.py b/pymongo/__init__.py index e116afc647..f00dcaf6dc 100644 --- a/pymongo/__init__.py +++ b/pymongo/__init__.py @@ -101,6 +101,7 @@ version_tuple = (3, 13, 0, ".dev0") + def get_version_string(): if isinstance(version_tuple[-1], str): return ".".join(map(str, version_tuple[:-1])) + version_tuple[-1] From 70671f57980758879d2666284d0c03a29b91cb29 Mon Sep 17 00:00:00 2001 From: julius Date: Wed, 16 Feb 2022 14:11:02 -0800 Subject: [PATCH 10/12] add tag for rapid --- .evergreen/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 575adcec01..f6719e928e 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -2028,6 +2028,10 @@ axes: display_name: "MongoDB 5.0" variables: VERSION: "5.0" + - id: "rapid" + display_name: "MongoDB rapid" + variables: + VERSION: "rapid" # Choice of Python runtime version - id: python-version From 77ecfb33ca918affa4c03dc4da1984874744ba9b Mon Sep 17 00:00:00 2001 From: julius Date: Wed, 16 Feb 2022 14:14:09 -0800 Subject: [PATCH 11/12] move vars down to test run --- .evergreen/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index f6719e928e..d00833fa87 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -1802,9 +1802,9 @@ tasks: TOPOLOGY: "sharded_cluster" LOAD_BALANCER: true - func: "run load-balancer" + - func: "run tests" vars: LOAD_BALANCER: true - - func: "run tests" # }}} - name: "coverage-report" tags: ["coverage"] From a2b383d5fa9f43dbc0f9256c171a3549eef495ed Mon Sep 17 00:00:00 2001 From: julius Date: Thu, 17 Feb 2022 12:56:57 -0800 Subject: [PATCH 12/12] remove another use of LOAD_BALANCER=True that was not needed --- .evergreen/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index d00833fa87..24ff0ee361 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -424,7 +424,6 @@ functions: fi if [ -n "${test_loadbalancer}" ]; then export TEST_LOADBALANCER=1 - export LOAD_BALANCER=1 export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}" export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" fi @@ -1803,8 +1802,6 @@ tasks: LOAD_BALANCER: true - func: "run load-balancer" - func: "run tests" - vars: - LOAD_BALANCER: true # }}} - name: "coverage-report" tags: ["coverage"]