Skip to content

Commit 4470309

Browse files
authored
PYTHON-2048 Improve error message for bulk_write failures due to unsupported storage enginge (#1600)
1 parent 8ff9c82 commit 4470309

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pymongo/bulk.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,19 @@ def _merge_command(
149149

150150
def _raise_bulk_write_error(full_result: _DocumentOut) -> NoReturn:
151151
"""Raise a BulkWriteError from the full bulk api result."""
152+
# retryWrites on MMAPv1 should raise an actionable error.
152153
if full_result["writeErrors"]:
153154
full_result["writeErrors"].sort(key=lambda error: error["index"])
155+
err = full_result["writeErrors"][0]
156+
code = err["code"]
157+
msg = err["errmsg"]
158+
if code == 20 and msg.startswith("Transaction numbers"):
159+
errmsg = (
160+
"This MongoDB deployment does not support "
161+
"retryable writes. Please add retryWrites=false "
162+
"to your connection string."
163+
)
164+
raise OperationFailure(errmsg, code, full_result)
154165
raise BulkWriteError(full_result)
155166

156167

0 commit comments

Comments
 (0)