From 72e214a4a3c619de7f121b54aeeb9680d21d6a4a Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Thu, 27 Feb 2025 15:39:53 -0800 Subject: [PATCH 1/3] PYTHON-5166 Fix db.command bulkWrite bug --- doc/changelog.rst | 22 +++++++++++++++++++++- pymongo/message.py | 2 +- test/asynchronous/test_database.py | 14 ++++++++++++++ test/test_database.py | 14 ++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index ee66bb178f..34c5fe42a8 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,7 +1,27 @@ Changelog ========= -Changes in Version 4.11.0 (YYYY/MM/DD) +Changes in Version 4.11.2 (YYYY/MM/DD) +-------------------------------------- + +Version 4.11.1 is a bug fix release. + +- Fixed a bug where :meth:`~pymongo.database.Database.command` would fail when attempting to run the bulkWrite command. + +Issues Resolved +............... + +See the `PyMongo 4.11.2 release notes in JIRA`_ for the list of resolved issues +in this release. + +.. _PyMongo 4.11.2 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=42506 + +Changes in Version 4.11.1 (2025/02/10) +-------------------------------------- + +- Fixed support for prebuilt ``ppc64le`` and ``s390x`` wheels. + +Changes in Version 4.11.0 (2025/01/28) -------------------------------------- .. warning:: PyMongo 4.11 drops support for Python 3.8 and PyPy 3.9: Python 3.9+ or PyPy 3.10+ is now required. diff --git a/pymongo/message.py b/pymongo/message.py index 10c9edb5cd..8e2fd6f990 100644 --- a/pymongo/message.py +++ b/pymongo/message.py @@ -105,7 +105,7 @@ "insert": "documents", "update": "updates", "delete": "deletes", - "bulkWrite": "bulkWrite", + "bulkWrite": "ops", } _UNICODE_REPLACE_CODEC_OPTIONS: CodecOptions[Mapping[str, Any]] = CodecOptions( diff --git a/test/asynchronous/test_database.py b/test/asynchronous/test_database.py index 55a8cc3ab2..80decdb5c7 100644 --- a/test/asynchronous/test_database.py +++ b/test/asynchronous/test_database.py @@ -430,6 +430,20 @@ async def test_command_with_regex(self): for doc in result["cursor"]["firstBatch"]: self.assertTrue(isinstance(doc["r"], Regex)) + async def test_command_bulkWrite(self): + # Ensure bulk write commands can be run directly via db.command(). + await self.client.admin.command( + { + "bulkWrite": 1, + "nsInfo": [{"ns": self.db.test.full_name}], + "ops": [{"insert": 0, "document": {}}], + } + ) + await self.db.command({"insert": "test", "documents": [{}]}) + await self.db.command({"update": "test", "updates": [{"q": {}, "u": {"$set": {"x": 1}}}]}) + await self.db.command({"delete": "test", "deletes": [{"q": {}, "limit": 1}]}) + await self.db.test.drop() + async def test_cursor_command(self): db = self.client.pymongo_test await db.test.drop() diff --git a/test/test_database.py b/test/test_database.py index aad9089bd8..0887e3d2aa 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -425,6 +425,20 @@ def test_command_with_regex(self): for doc in result["cursor"]["firstBatch"]: self.assertTrue(isinstance(doc["r"], Regex)) + def test_command_bulkWrite(self): + # Ensure bulk write commands can be run directly via db.command(). + self.client.admin.command( + { + "bulkWrite": 1, + "nsInfo": [{"ns": self.db.test.full_name}], + "ops": [{"insert": 0, "document": {}}], + } + ) + self.db.command({"insert": "test", "documents": [{}]}) + self.db.command({"update": "test", "updates": [{"q": {}, "u": {"$set": {"x": 1}}}]}) + self.db.command({"delete": "test", "deletes": [{"q": {}, "limit": 1}]}) + self.db.test.drop() + def test_cursor_command(self): db = self.client.pymongo_test db.test.drop() From b38ee003625fdcbbc6d07f882227666989684d78 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Thu, 27 Feb 2025 15:49:04 -0800 Subject: [PATCH 2/3] PYTHON-5166 Fix test to check for 8.0 for bulkWrite command support --- test/asynchronous/test_database.py | 15 ++++++++------- test/test_database.py | 15 ++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/test/asynchronous/test_database.py b/test/asynchronous/test_database.py index 80decdb5c7..2bbf763ab3 100644 --- a/test/asynchronous/test_database.py +++ b/test/asynchronous/test_database.py @@ -432,13 +432,14 @@ async def test_command_with_regex(self): async def test_command_bulkWrite(self): # Ensure bulk write commands can be run directly via db.command(). - await self.client.admin.command( - { - "bulkWrite": 1, - "nsInfo": [{"ns": self.db.test.full_name}], - "ops": [{"insert": 0, "document": {}}], - } - ) + if async_client_context.version.at_least(8, 0): + await self.client.admin.command( + { + "bulkWrite": 1, + "nsInfo": [{"ns": self.db.test.full_name}], + "ops": [{"insert": 0, "document": {}}], + } + ) await self.db.command({"insert": "test", "documents": [{}]}) await self.db.command({"update": "test", "updates": [{"q": {}, "u": {"$set": {"x": 1}}}]}) await self.db.command({"delete": "test", "deletes": [{"q": {}, "limit": 1}]}) diff --git a/test/test_database.py b/test/test_database.py index 0887e3d2aa..48cca921b1 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -427,13 +427,14 @@ def test_command_with_regex(self): def test_command_bulkWrite(self): # Ensure bulk write commands can be run directly via db.command(). - self.client.admin.command( - { - "bulkWrite": 1, - "nsInfo": [{"ns": self.db.test.full_name}], - "ops": [{"insert": 0, "document": {}}], - } - ) + if client_context.version.at_least(8, 0): + self.client.admin.command( + { + "bulkWrite": 1, + "nsInfo": [{"ns": self.db.test.full_name}], + "ops": [{"insert": 0, "document": {}}], + } + ) self.db.command({"insert": "test", "documents": [{}]}) self.db.command({"update": "test", "updates": [{"q": {}, "u": {"$set": {"x": 1}}}]}) self.db.command({"delete": "test", "deletes": [{"q": {}, "limit": 1}]}) From 2d63fc81b1506d4c6c47802efb2071f56af68e5b Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Thu, 27 Feb 2025 15:50:55 -0800 Subject: [PATCH 3/3] PYTHON-5166 Fix changelog --- doc/changelog.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 34c5fe42a8..fcad842def 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -4,15 +4,14 @@ Changelog Changes in Version 4.11.2 (YYYY/MM/DD) -------------------------------------- -Version 4.11.1 is a bug fix release. +Version 4.11.2 is a bug fix release. - Fixed a bug where :meth:`~pymongo.database.Database.command` would fail when attempting to run the bulkWrite command. Issues Resolved ............... -See the `PyMongo 4.11.2 release notes in JIRA`_ for the list of resolved issues -in this release. +See the `PyMongo 4.11.2 release notes in JIRA`_ for the list of resolved issues in this release. .. _PyMongo 4.11.2 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=42506