Skip to content

Commit b10921e

Browse files
committed
PYTHON-2544 Do not check error messages when an error code is present (#574)
Add 10058 as a "not master" error code to account for MongoDB<=3.2 errors. (cherry picked from commit de7c7b8)
1 parent 08aed3c commit b10921e

14 files changed

+1056
-10
lines changed

pymongo/helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# "node is recovering" error codes (of which the "node is shutting down"
3939
# errors are a subset).
4040
_NOT_MASTER_CODES = frozenset([
41+
10058, # LegacyNotPrimary <=3.2 "not master" error code
4142
10107, # NotMaster
4243
13435, # NotMasterNoSlaveOk
4344
11602, # InterruptedDueToReplStateChange
@@ -147,8 +148,9 @@ def _check_command_response(response, max_wire_version,
147148
return
148149

149150
# Server is "not master" or "recovering"
150-
if code in _NOT_MASTER_CODES:
151-
raise NotMasterError(errmsg, response)
151+
if code is not None:
152+
if code in _NOT_MASTER_CODES:
153+
raise NotMasterError(errmsg, response)
152154
elif "not master" in errmsg or "node is recovering" in errmsg:
153155
raise NotMasterError(errmsg, response)
154156

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"description": "Non-stale topologyVersion greater LegacyNotPrimary error",
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": "Non-stale topologyVersion greater LegacyNotPrimary error marks server Unknown",
55+
"applicationErrors": [
56+
{
57+
"address": "a:27017",
58+
"when": "afterHandshakeCompletes",
59+
"maxWireVersion": 9,
60+
"type": "command",
61+
"response": {
62+
"ok": 0,
63+
"errmsg": "LegacyNotPrimary",
64+
"code": 10058,
65+
"topologyVersion": {
66+
"processId": {
67+
"$oid": "000000000000000000000001"
68+
},
69+
"counter": {
70+
"$numberLong": "2"
71+
}
72+
}
73+
}
74+
}
75+
],
76+
"outcome": {
77+
"servers": {
78+
"a:27017": {
79+
"type": "Unknown",
80+
"topologyVersion": {
81+
"processId": {
82+
"$oid": "000000000000000000000001"
83+
},
84+
"counter": {
85+
"$numberLong": "2"
86+
}
87+
},
88+
"pool": {
89+
"generation": 0
90+
}
91+
}
92+
},
93+
"topologyType": "ReplicaSetNoPrimary",
94+
"logicalSessionTimeoutMinutes": null,
95+
"setName": "rs"
96+
}
97+
}
98+
]
99+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"description": "Non-stale topologyVersion missing LegacyNotPrimary error",
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": "Non-stale topologyVersion missing LegacyNotPrimary error marks server Unknown",
55+
"applicationErrors": [
56+
{
57+
"address": "a:27017",
58+
"when": "afterHandshakeCompletes",
59+
"maxWireVersion": 9,
60+
"type": "command",
61+
"response": {
62+
"ok": 0,
63+
"errmsg": "LegacyNotPrimary",
64+
"code": 10058
65+
}
66+
}
67+
],
68+
"outcome": {
69+
"servers": {
70+
"a:27017": {
71+
"type": "Unknown",
72+
"topologyVersion": null,
73+
"pool": {
74+
"generation": 0
75+
}
76+
}
77+
},
78+
"topologyType": "ReplicaSetNoPrimary",
79+
"logicalSessionTimeoutMinutes": null,
80+
"setName": "rs"
81+
}
82+
}
83+
]
84+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"description": "Non-stale topologyVersion proccessId changed LegacyNotPrimary error",
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": "Non-stale topologyVersion proccessId changed LegacyNotPrimary error marks server Unknown",
55+
"applicationErrors": [
56+
{
57+
"address": "a:27017",
58+
"when": "afterHandshakeCompletes",
59+
"maxWireVersion": 9,
60+
"type": "command",
61+
"response": {
62+
"ok": 0,
63+
"errmsg": "LegacyNotPrimary",
64+
"code": 10058,
65+
"topologyVersion": {
66+
"processId": {
67+
"$oid": "000000000000000000000002"
68+
},
69+
"counter": {
70+
"$numberLong": "1"
71+
}
72+
}
73+
}
74+
}
75+
],
76+
"outcome": {
77+
"servers": {
78+
"a:27017": {
79+
"type": "Unknown",
80+
"topologyVersion": {
81+
"processId": {
82+
"$oid": "000000000000000000000002"
83+
},
84+
"counter": {
85+
"$numberLong": "1"
86+
}
87+
},
88+
"pool": {
89+
"generation": 0
90+
}
91+
}
92+
},
93+
"topologyType": "ReplicaSetNoPrimary",
94+
"logicalSessionTimeoutMinutes": null,
95+
"setName": "rs"
96+
}
97+
}
98+
]
99+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"description": "Post-4.2 LegacyNotPrimary error",
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": 8
19+
}
20+
]
21+
],
22+
"outcome": {
23+
"servers": {
24+
"a:27017": {
25+
"type": "RSPrimary",
26+
"setName": "rs",
27+
"topologyVersion": null,
28+
"pool": {
29+
"generation": 0
30+
}
31+
}
32+
},
33+
"topologyType": "ReplicaSetWithPrimary",
34+
"logicalSessionTimeoutMinutes": null,
35+
"setName": "rs"
36+
}
37+
},
38+
{
39+
"description": "Post-4.2 LegacyNotPrimary error marks server Unknown",
40+
"applicationErrors": [
41+
{
42+
"address": "a:27017",
43+
"when": "afterHandshakeCompletes",
44+
"maxWireVersion": 8,
45+
"type": "command",
46+
"response": {
47+
"ok": 0,
48+
"errmsg": "LegacyNotPrimary",
49+
"code": 10058
50+
}
51+
}
52+
],
53+
"outcome": {
54+
"servers": {
55+
"a:27017": {
56+
"type": "Unknown",
57+
"topologyVersion": null,
58+
"pool": {
59+
"generation": 0
60+
}
61+
}
62+
},
63+
"topologyType": "ReplicaSetNoPrimary",
64+
"logicalSessionTimeoutMinutes": null,
65+
"setName": "rs"
66+
}
67+
}
68+
]
69+
}

0 commit comments

Comments
 (0)