Skip to content

Commit cad4c25

Browse files
committed
PYTHON-2543 Do not mark a server unknown from a "writeErrors" response (#570)
(cherry picked from commit 20d5a9c)
1 parent be6822b commit cad4c25

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
@@ -39,7 +39,8 @@
3939
NetworkTimeout,
4040
NotMasterError,
4141
OperationFailure,
42-
ServerSelectionTimeoutError)
42+
ServerSelectionTimeoutError,
43+
WriteError)
4344
from pymongo.monitor import SrvMonitor
4445
from pymongo.monotonic import time as _time
4546
from pymongo.server import Server
@@ -574,6 +575,9 @@ def _handle_error(self, address, err_ctx):
574575
# operation fails because of any network error besides a socket
575576
# timeout...."
576577
return
578+
elif issubclass(exc_type, WriteError):
579+
# Ignore writeErrors.
580+
return
577581
elif issubclass(exc_type, NotMasterError):
578582
# As per the SDAM spec if:
579583
# - 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
@@ -112,6 +113,7 @@ def got_app_error(topology, app_error):
112113
try:
113114
if error_type == 'command':
114115
_check_command_response(app_error['response'], max_wire_version)
116+
_check_write_command_response(app_error['response'])
115117
elif error_type == 'network':
116118
raise AutoReconnect('mock non-timeout network error')
117119
elif error_type == 'timeout':

0 commit comments

Comments
 (0)