Skip to content

Commit 72e214a

Browse files
committed
PYTHON-5166 Fix db.command bulkWrite bug
1 parent e52965e commit 72e214a

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

doc/changelog.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
Changelog
22
=========
33

4-
Changes in Version 4.11.0 (YYYY/MM/DD)
4+
Changes in Version 4.11.2 (YYYY/MM/DD)
5+
--------------------------------------
6+
7+
Version 4.11.1 is a bug fix release.
8+
9+
- Fixed a bug where :meth:`~pymongo.database.Database.command` would fail when attempting to run the bulkWrite command.
10+
11+
Issues Resolved
12+
...............
13+
14+
See the `PyMongo 4.11.2 release notes in JIRA`_ for the list of resolved issues
15+
in this release.
16+
17+
.. _PyMongo 4.11.2 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=42506
18+
19+
Changes in Version 4.11.1 (2025/02/10)
20+
--------------------------------------
21+
22+
- Fixed support for prebuilt ``ppc64le`` and ``s390x`` wheels.
23+
24+
Changes in Version 4.11.0 (2025/01/28)
525
--------------------------------------
626

727
.. warning:: PyMongo 4.11 drops support for Python 3.8 and PyPy 3.9: Python 3.9+ or PyPy 3.10+ is now required.

pymongo/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"insert": "documents",
106106
"update": "updates",
107107
"delete": "deletes",
108-
"bulkWrite": "bulkWrite",
108+
"bulkWrite": "ops",
109109
}
110110

111111
_UNICODE_REPLACE_CODEC_OPTIONS: CodecOptions[Mapping[str, Any]] = CodecOptions(

test/asynchronous/test_database.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ async def test_command_with_regex(self):
430430
for doc in result["cursor"]["firstBatch"]:
431431
self.assertTrue(isinstance(doc["r"], Regex))
432432

433+
async def test_command_bulkWrite(self):
434+
# Ensure bulk write commands can be run directly via db.command().
435+
await self.client.admin.command(
436+
{
437+
"bulkWrite": 1,
438+
"nsInfo": [{"ns": self.db.test.full_name}],
439+
"ops": [{"insert": 0, "document": {}}],
440+
}
441+
)
442+
await self.db.command({"insert": "test", "documents": [{}]})
443+
await self.db.command({"update": "test", "updates": [{"q": {}, "u": {"$set": {"x": 1}}}]})
444+
await self.db.command({"delete": "test", "deletes": [{"q": {}, "limit": 1}]})
445+
await self.db.test.drop()
446+
433447
async def test_cursor_command(self):
434448
db = self.client.pymongo_test
435449
await db.test.drop()

test/test_database.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ def test_command_with_regex(self):
425425
for doc in result["cursor"]["firstBatch"]:
426426
self.assertTrue(isinstance(doc["r"], Regex))
427427

428+
def test_command_bulkWrite(self):
429+
# Ensure bulk write commands can be run directly via db.command().
430+
self.client.admin.command(
431+
{
432+
"bulkWrite": 1,
433+
"nsInfo": [{"ns": self.db.test.full_name}],
434+
"ops": [{"insert": 0, "document": {}}],
435+
}
436+
)
437+
self.db.command({"insert": "test", "documents": [{}]})
438+
self.db.command({"update": "test", "updates": [{"q": {}, "u": {"$set": {"x": 1}}}]})
439+
self.db.command({"delete": "test", "deletes": [{"q": {}, "limit": 1}]})
440+
self.db.test.drop()
441+
428442
def test_cursor_command(self):
429443
db = self.client.pymongo_test
430444
db.test.drop()

0 commit comments

Comments
 (0)