Skip to content

Commit fb7533e

Browse files
committed
PYTHON-2099 Make ExceededTimeLimit a retryable writes error
Reinstate DuplicateKey code assertions.
1 parent a4f38d7 commit fb7533e

File tree

6 files changed

+63
-5
lines changed

6 files changed

+63
-5
lines changed

pymongo/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
6, # HostUnreachable
5151
89, # NetworkTimeout
5252
9001, # SocketException
53+
262, # ExceededTimeLimit
5354
])
5455
_UUNDER = u"_"
5556

test/retryable_writes/insertOne-serverErrors.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,54 @@
575575
}
576576
}
577577
},
578+
{
579+
"description": "InsertOne succeeds after ExceededTimeLimit",
580+
"failPoint": {
581+
"configureFailPoint": "failCommand",
582+
"mode": {
583+
"times": 1
584+
},
585+
"data": {
586+
"failCommands": [
587+
"insert"
588+
],
589+
"writeConcernError": {
590+
"code": 262,
591+
"closeConnection": false
592+
}
593+
}
594+
},
595+
"operation": {
596+
"name": "insertOne",
597+
"arguments": {
598+
"document": {
599+
"_id": 3,
600+
"x": 33
601+
}
602+
}
603+
},
604+
"outcome": {
605+
"result": {
606+
"insertedId": 3
607+
},
608+
"collection": {
609+
"data": [
610+
{
611+
"_id": 1,
612+
"x": 11
613+
},
614+
{
615+
"_id": 2,
616+
"x": 22
617+
},
618+
{
619+
"_id": 3,
620+
"x": 33
621+
}
622+
]
623+
}
624+
}
625+
},
578626
{
579627
"description": "InsertOne fails after Interrupted",
580628
"failPoint": {

test/transactions-convenient-api/callback-retry.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@
235235
"errorLabelsOmit": [
236236
"TransientTransactionError",
237237
"UnknownTransactionCommitResult"
238-
]
238+
],
239+
"errorContains": "E11000"
239240
}
240241
}
241242
],

test/transactions/abort.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@
458458
"errorLabelsOmit": [
459459
"TransientTransactionError",
460460
"UnknownTransactionCommitResult"
461-
]
461+
],
462+
"errorContains": "E11000"
462463
}
463464
},
464465
{

test/transactions/error-labels.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"errorLabelsOmit": [
4343
"TransientTransactionError",
4444
"UnknownTransactionCommitResult"
45-
]
45+
],
46+
"errorContains": "E11000"
4647
}
4748
},
4849
{

test/utils_spec_runner.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
operations)
3333
from pymongo.command_cursor import CommandCursor
3434
from pymongo.cursor import Cursor
35-
from pymongo.errors import (OperationFailure, PyMongoError)
35+
from pymongo.errors import (BulkWriteError,
36+
OperationFailure,
37+
PyMongoError)
3638
from pymongo.read_concern import ReadConcern
3739
from pymongo.read_preferences import ReadPreference
3840
from pymongo.results import _WriteResult, BulkWriteResult
@@ -375,8 +377,12 @@ def run_operations(self, sessions, collection, ops,
375377
self.run_operation(sessions, collection, op.copy())
376378

377379
if expect_error_message(expected_result):
380+
if isinstance(context.exception, BulkWriteError):
381+
errmsg = str(context.exception.details).lower()
382+
else:
383+
errmsg = str(context.exception).lower()
378384
self.assertIn(expected_result['errorContains'].lower(),
379-
str(context.exception).lower())
385+
errmsg)
380386
if expect_error_code(expected_result):
381387
self.assertEqual(expected_result['errorCodeName'],
382388
context.exception.details.get('codeName'))

0 commit comments

Comments
 (0)