Skip to content

Commit 20d5a9c

Browse files
authored
PYTHON-2543 Do not mark a server unknown from a "writeErrors" response (#570)
1 parent 3e97712 commit 20d5a9c

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

pymongo/topology.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
NotMasterError,
3333
OperationFailure,
3434
PyMongoError,
35-
ServerSelectionTimeoutError)
35+
ServerSelectionTimeoutError,
36+
WriteError)
3637
from pymongo.monitor import SrvMonitor
3738
from pymongo.pool import PoolOptions
3839
from pymongo.server import Server
@@ -578,6 +579,9 @@ def _handle_error(self, address, err_ctx):
578579
# operation fails because of any network error besides a socket
579580
# timeout...."
580581
return
582+
elif issubclass(exc_type, WriteError):
583+
# Ignore writeErrors.
584+
return
581585
elif issubclass(exc_type, NotMasterError):
582586
# As per the SDAM spec if:
583587
# - the server sees a "not master" error, and
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"description": "writeErrors field is ignored",
3+
"uri": "mongodb://a/?replicaSet=rs",
4+
"phases": [
5+
{
6+
"description": "Primary A is discovered",
7+
"responses": [
8+
[
9+
"a:27017",
10+
{
11+
"ok": 1,
12+
"ismaster": true,
13+
"hosts": [
14+
"a:27017"
15+
],
16+
"setName": "rs",
17+
"minWireVersion": 0,
18+
"maxWireVersion": 9,
19+
"topologyVersion": {
20+
"processId": {
21+
"$oid": "000000000000000000000001"
22+
},
23+
"counter": {
24+
"$numberLong": "1"
25+
}
26+
}
27+
}
28+
]
29+
],
30+
"outcome": {
31+
"servers": {
32+
"a:27017": {
33+
"type": "RSPrimary",
34+
"setName": "rs",
35+
"topologyVersion": {
36+
"processId": {
37+
"$oid": "000000000000000000000001"
38+
},
39+
"counter": {
40+
"$numberLong": "1"
41+
}
42+
},
43+
"pool": {
44+
"generation": 0
45+
}
46+
}
47+
},
48+
"topologyType": "ReplicaSetWithPrimary",
49+
"logicalSessionTimeoutMinutes": null,
50+
"setName": "rs"
51+
}
52+
},
53+
{
54+
"description": "Ignore command error with writeErrors field",
55+
"applicationErrors": [
56+
{
57+
"address": "a:27017",
58+
"when": "afterHandshakeCompletes",
59+
"maxWireVersion": 9,
60+
"type": "command",
61+
"response": {
62+
"ok": 1,
63+
"writeErrors": [
64+
{
65+
"errmsg": "NotMasterNoSlaveOk",
66+
"code": 13435
67+
}
68+
]
69+
}
70+
}
71+
],
72+
"outcome": {
73+
"servers": {
74+
"a:27017": {
75+
"type": "RSPrimary",
76+
"setName": "rs",
77+
"topologyVersion": {
78+
"processId": {
79+
"$oid": "000000000000000000000001"
80+
},
81+
"counter": {
82+
"$numberLong": "1"
83+
}
84+
},
85+
"pool": {
86+
"generation": 0
87+
}
88+
}
89+
},
90+
"topologyType": "ReplicaSetWithPrimary",
91+
"logicalSessionTimeoutMinutes": null,
92+
"setName": "rs"
93+
}
94+
}
95+
]
96+
}

test/test_discovery_and_monitoring.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
NetworkTimeout,
3030
NotMasterError,
3131
OperationFailure)
32-
from pymongo.helpers import _check_command_response
32+
from pymongo.helpers import (_check_command_response,
33+
_check_write_command_response)
3334
from pymongo.ismaster import IsMaster
3435
from pymongo.server_description import ServerDescription, SERVER_TYPE
3536
from pymongo.settings import TopologySettings
@@ -94,6 +95,7 @@ def got_app_error(topology, app_error):
9495
try:
9596
if error_type == 'command':
9697
_check_command_response(app_error['response'], max_wire_version)
98+
_check_write_command_response(app_error['response'])
9799
elif error_type == 'network':
98100
raise AutoReconnect('mock non-timeout network error')
99101
elif error_type == 'timeout':

0 commit comments

Comments
 (0)