Skip to content

Commit 2de0d88

Browse files
committed
remove unintended changes and fix retryable?
1 parent 69f9447 commit 2de0d88

File tree

6 files changed

+24
-40
lines changed

6 files changed

+24
-40
lines changed

pymongo/asynchronous/bulk.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,6 @@ def bulk_ctx_class(self) -> Type[_BulkWriteContext]:
130130
self.is_encrypted = False
131131
return _BulkWriteContext
132132

133-
# @property
134-
# def is_retryable(self) -> bool:
135-
# if self.current_run:
136-
# return self.current_run.is_retryable
137-
# return True
138-
#
139-
# @property
140-
# def retrying(self) -> bool:
141-
# if self.current_run:
142-
# return self.current_run.retrying
143-
# return False
144-
#
145-
# @property
146-
# def started_retryable_write(self) -> bool:
147-
# if self.current_run:
148-
# return self.current_run.started_retryable_write
149-
# return False
150-
151133
def add_insert(self, document: _DocumentOut) -> bool:
152134
"""Add an insert document to the list of ops."""
153135
validate_is_document_type("document", document)
@@ -579,7 +561,6 @@ async def _execute_command(
579561
# Start a new retryable write unless one was already
580562
# started for this command.
581563
if retryable and self.is_retryable and not self.started_retryable_write:
582-
# print("starting retrayable write")
583564
session._start_retryable_write()
584565
self.started_retryable_write = True
585566
session._apply_to(
@@ -596,6 +577,7 @@ async def _execute_command(
596577
await self.validate_batch(conn, write_concern)
597578
if write_concern.acknowledged:
598579
result, to_send = await self._execute_batch(bwc, cmd, ops, client)
580+
599581
# Retryable writeConcernErrors halt the execution of this run.
600582
wce = result.get("writeConcernError", {})
601583
if wce.get("code", 0) in _RETRYABLE_ERROR_CODES:
@@ -604,7 +586,9 @@ async def _execute_command(
604586
full = copy.deepcopy(full_result)
605587
_merge_command(run, full, run.idx_offset, result)
606588
_raise_bulk_write_error(full)
589+
607590
_merge_command(run, full_result, run.idx_offset, result)
591+
608592
# We're no longer in a retry once a command succeeds.
609593
self.retrying = False
610594
self.started_retryable_write = False

pymongo/asynchronous/client_bulk.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,12 @@ async def _execute_command(
535535
if session:
536536
# Start a new retryable write unless one was already
537537
# started for this command.
538-
if retryable and self.is_retryable and not self.started_retryable_write:
538+
if (
539+
retryable
540+
and self.is_retryable
541+
and not self.started_retryable_write
542+
and not session.in_transaction
543+
):
539544
session._start_retryable_write()
540545
self.started_retryable_write = True
541546
session._apply_to(

pymongo/asynchronous/mongo_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,9 @@ async def _retry_with_session(
19471947
"""
19481948
# Ensure that the options supports retry_writes and there is a valid session not in
19491949
# transaction, otherwise, we will not support retry behavior for this txn.
1950+
retryable = bool(
1951+
retryable and self.options.retry_writes and session and not session.in_transaction
1952+
)
19501953
return await self._retry_internal(
19511954
func=func,
19521955
session=session,

pymongo/synchronous/bulk.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,6 @@ def bulk_ctx_class(self) -> Type[_BulkWriteContext]:
130130
self.is_encrypted = False
131131
return _BulkWriteContext
132132

133-
# @property
134-
# def is_retryable(self) -> bool:
135-
# if self.current_run:
136-
# return self.current_run.is_retryable
137-
# return True
138-
#
139-
# @property
140-
# def retrying(self) -> bool:
141-
# if self.current_run:
142-
# return self.current_run.retrying
143-
# return False
144-
#
145-
# @property
146-
# def started_retryable_write(self) -> bool:
147-
# if self.current_run:
148-
# return self.current_run.started_retryable_write
149-
# return False
150-
151133
def add_insert(self, document: _DocumentOut) -> bool:
152134
"""Add an insert document to the list of ops."""
153135
validate_is_document_type("document", document)
@@ -579,7 +561,6 @@ def _execute_command(
579561
# Start a new retryable write unless one was already
580562
# started for this command.
581563
if retryable and self.is_retryable and not self.started_retryable_write:
582-
# print("starting retrayable write")
583564
session._start_retryable_write()
584565
self.started_retryable_write = True
585566
session._apply_to(
@@ -596,6 +577,7 @@ def _execute_command(
596577
self.validate_batch(conn, write_concern)
597578
if write_concern.acknowledged:
598579
result, to_send = self._execute_batch(bwc, cmd, ops, client)
580+
599581
# Retryable writeConcernErrors halt the execution of this run.
600582
wce = result.get("writeConcernError", {})
601583
if wce.get("code", 0) in _RETRYABLE_ERROR_CODES:
@@ -604,7 +586,9 @@ def _execute_command(
604586
full = copy.deepcopy(full_result)
605587
_merge_command(run, full, run.idx_offset, result)
606588
_raise_bulk_write_error(full)
589+
607590
_merge_command(run, full_result, run.idx_offset, result)
591+
608592
# We're no longer in a retry once a command succeeds.
609593
self.retrying = False
610594
self.started_retryable_write = False

pymongo/synchronous/client_bulk.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,12 @@ def _execute_command(
533533
if session:
534534
# Start a new retryable write unless one was already
535535
# started for this command.
536-
if retryable and self.is_retryable and not self.started_retryable_write:
536+
if (
537+
retryable
538+
and self.is_retryable
539+
and not self.started_retryable_write
540+
and not session.in_transaction
541+
):
537542
session._start_retryable_write()
538543
self.started_retryable_write = True
539544
session._apply_to(

pymongo/synchronous/mongo_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,9 @@ def _retry_with_session(
19411941
"""
19421942
# Ensure that the options supports retry_writes and there is a valid session not in
19431943
# transaction, otherwise, we will not support retry behavior for this txn.
1944+
retryable = bool(
1945+
retryable and self.options.retry_writes and session and not session.in_transaction
1946+
)
19441947
return self._retry_internal(
19451948
func=func,
19461949
session=session,

0 commit comments

Comments
 (0)