Skip to content

Commit 2332d69

Browse files
authored
PYTHON-4807 - Update changelog + remove dead code (mongodb#1984)
1 parent 92d6a73 commit 2332d69

File tree

3 files changed

+14
-88
lines changed

3 files changed

+14
-88
lines changed

doc/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PyMongo 4.11 brings a number of changes including:
2424
:meth:`~pymongo.collection.Collection.update_one`, :meth:`~pymongo.collection.Collection.replace_one`,
2525
:class:`~pymongo.operations.UpdateOne`, and
2626
:class:`~pymongo.operations.UpdateMany`,
27+
- :meth:`~pymongo.mongo_client.MongoClient.bulk_write` and
28+
:meth:`~pymongo.asynchronous.mongo_client.AsyncMongoClient.bulk_write` now throw an error
29+
when ``ordered=True`` or ``verboseResults=True`` are used with unacknowledged writes.
30+
These are unavoidable breaking changes.
2731

2832
Issues Resolved
2933
...............

pymongo/asynchronous/client_bulk.py

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,11 @@ async def retryable_bulk(
681681
_throw_client_bulk_write_exception(full_result, self.verbose_results)
682682
return full_result
683683

684-
async def execute_command_unack_unordered(
684+
async def execute_command_unack(
685685
self,
686686
conn: AsyncConnection,
687687
) -> None:
688-
"""Execute commands with OP_MSG and w=0 writeConcern, unordered."""
688+
"""Execute commands with OP_MSG and w=0 writeConcern. Always unordered."""
689689
db_name = "admin"
690690
cmd_name = "bulkWrite"
691691
listeners = self.client._event_listeners
@@ -704,8 +704,8 @@ async def execute_command_unack_unordered(
704704
while self.idx_offset < self.total_ops:
705705
# Construct the server command, specifying the relevant options.
706706
cmd = {"bulkWrite": 1}
707-
cmd["errorsOnly"] = not self.verbose_results
708-
cmd["ordered"] = self.ordered # type: ignore[assignment]
707+
cmd["errorsOnly"] = True
708+
cmd["ordered"] = False
709709
if self.bypass_doc_val is not None:
710710
cmd["bypassDocumentValidation"] = self.bypass_doc_val
711711
cmd["writeConcern"] = {"w": 0} # type: ignore[assignment]
@@ -723,43 +723,6 @@ async def execute_command_unack_unordered(
723723

724724
self.idx_offset += len(to_send_ops)
725725

726-
async def execute_command_unack_ordered(
727-
self,
728-
conn: AsyncConnection,
729-
) -> None:
730-
"""Execute commands with OP_MSG and w=0 WriteConcern, ordered."""
731-
full_result: MutableMapping[str, Any] = {
732-
"anySuccessful": False,
733-
"error": None,
734-
"writeErrors": [],
735-
"writeConcernErrors": [],
736-
"nInserted": 0,
737-
"nUpserted": 0,
738-
"nMatched": 0,
739-
"nModified": 0,
740-
"nDeleted": 0,
741-
"insertResults": {},
742-
"updateResults": {},
743-
"deleteResults": {},
744-
}
745-
# Ordered bulk writes have to be acknowledged so that we stop
746-
# processing at the first error, even when the application
747-
# specified unacknowledged writeConcern.
748-
initial_write_concern = WriteConcern()
749-
op_id = _randint()
750-
try:
751-
await self._execute_command(
752-
initial_write_concern,
753-
None,
754-
conn,
755-
op_id,
756-
False,
757-
full_result,
758-
self.write_concern,
759-
)
760-
except OperationFailure:
761-
pass
762-
763726
async def execute_no_results(
764727
self,
765728
conn: AsyncConnection,
@@ -775,9 +738,7 @@ async def execute_no_results(
775738
"Cannot set bypass_document_validation with unacknowledged write concern"
776739
)
777740

778-
if self.ordered:
779-
return await self.execute_command_unack_ordered(conn)
780-
return await self.execute_command_unack_unordered(conn)
741+
return await self.execute_command_unack(conn)
781742

782743
async def execute(
783744
self,

pymongo/synchronous/client_bulk.py

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,11 @@ def retryable_bulk(
679679
_throw_client_bulk_write_exception(full_result, self.verbose_results)
680680
return full_result
681681

682-
def execute_command_unack_unordered(
682+
def execute_command_unack(
683683
self,
684684
conn: Connection,
685685
) -> None:
686-
"""Execute commands with OP_MSG and w=0 writeConcern, unordered."""
686+
"""Execute commands with OP_MSG and w=0 writeConcern. Always unordered."""
687687
db_name = "admin"
688688
cmd_name = "bulkWrite"
689689
listeners = self.client._event_listeners
@@ -702,8 +702,8 @@ def execute_command_unack_unordered(
702702
while self.idx_offset < self.total_ops:
703703
# Construct the server command, specifying the relevant options.
704704
cmd = {"bulkWrite": 1}
705-
cmd["errorsOnly"] = not self.verbose_results
706-
cmd["ordered"] = self.ordered # type: ignore[assignment]
705+
cmd["errorsOnly"] = True
706+
cmd["ordered"] = False
707707
if self.bypass_doc_val is not None:
708708
cmd["bypassDocumentValidation"] = self.bypass_doc_val
709709
cmd["writeConcern"] = {"w": 0} # type: ignore[assignment]
@@ -721,43 +721,6 @@ def execute_command_unack_unordered(
721721

722722
self.idx_offset += len(to_send_ops)
723723

724-
def execute_command_unack_ordered(
725-
self,
726-
conn: Connection,
727-
) -> None:
728-
"""Execute commands with OP_MSG and w=0 WriteConcern, ordered."""
729-
full_result: MutableMapping[str, Any] = {
730-
"anySuccessful": False,
731-
"error": None,
732-
"writeErrors": [],
733-
"writeConcernErrors": [],
734-
"nInserted": 0,
735-
"nUpserted": 0,
736-
"nMatched": 0,
737-
"nModified": 0,
738-
"nDeleted": 0,
739-
"insertResults": {},
740-
"updateResults": {},
741-
"deleteResults": {},
742-
}
743-
# Ordered bulk writes have to be acknowledged so that we stop
744-
# processing at the first error, even when the application
745-
# specified unacknowledged writeConcern.
746-
initial_write_concern = WriteConcern()
747-
op_id = _randint()
748-
try:
749-
self._execute_command(
750-
initial_write_concern,
751-
None,
752-
conn,
753-
op_id,
754-
False,
755-
full_result,
756-
self.write_concern,
757-
)
758-
except OperationFailure:
759-
pass
760-
761724
def execute_no_results(
762725
self,
763726
conn: Connection,
@@ -773,9 +736,7 @@ def execute_no_results(
773736
"Cannot set bypass_document_validation with unacknowledged write concern"
774737
)
775738

776-
if self.ordered:
777-
return self.execute_command_unack_ordered(conn)
778-
return self.execute_command_unack_unordered(conn)
739+
return self.execute_command_unack(conn)
779740

780741
def execute(
781742
self,

0 commit comments

Comments
 (0)