Skip to content

Commit 8d41a38

Browse files
committed
PYTHON-2179 Raise client-side error if an index hint is specified for an unacknowledged operation
1 parent ced7d52 commit 8d41a38

11 files changed

+1197
-0
lines changed

pymongo/collection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,6 +2933,9 @@ def _find_and_modify(session, sock_info, retryable_write):
29332933
if sock_info.max_wire_version < 8:
29342934
raise ConfigurationError(
29352935
'Must be connected to MongoDB 4.2+ to use hint.')
2936+
if not write_concern.acknowledged:
2937+
raise ConfigurationError(
2938+
'hint is unsupported for unacknowledged writes.')
29362939
cmd['hint'] = hint
29372940
if (sock_info.max_wire_version >= 4 and
29382941
not write_concern.is_server_default):
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"data": [
3+
{
4+
"_id": 1,
5+
"x": 11
6+
},
7+
{
8+
"_id": 2,
9+
"x": 22
10+
},
11+
{
12+
"_id": 3,
13+
"x": 33
14+
},
15+
{
16+
"_id": 4,
17+
"x": 44
18+
}
19+
],
20+
"collection_name": "BulkWrite_delete_hint",
21+
"tests": [
22+
{
23+
"description": "Unacknowledged bulkWrite deleteOne with hints fails with client-side error",
24+
"operations": [
25+
{
26+
"name": "bulkWrite",
27+
"collectionOptions": {
28+
"writeConcern": {
29+
"w": 0
30+
}
31+
},
32+
"arguments": {
33+
"requests": [
34+
{
35+
"name": "deleteOne",
36+
"arguments": {
37+
"filter": {
38+
"_id": 1
39+
},
40+
"hint": "_id_"
41+
}
42+
},
43+
{
44+
"name": "deleteOne",
45+
"arguments": {
46+
"filter": {
47+
"_id": 2
48+
},
49+
"hint": {
50+
"_id": 1
51+
}
52+
}
53+
}
54+
],
55+
"options": {
56+
"ordered": true
57+
}
58+
},
59+
"error": true
60+
}
61+
],
62+
"expectations": [],
63+
"outcome": {
64+
"collection": {
65+
"data": [
66+
{
67+
"_id": 1,
68+
"x": 11
69+
},
70+
{
71+
"_id": 2,
72+
"x": 22
73+
},
74+
{
75+
"_id": 3,
76+
"x": 33
77+
},
78+
{
79+
"_id": 4,
80+
"x": 44
81+
}
82+
]
83+
}
84+
}
85+
},
86+
{
87+
"description": "Unacknowledged bulkWrite deleteMany with hints fails with client-side error",
88+
"operations": [
89+
{
90+
"name": "bulkWrite",
91+
"collectionOptions": {
92+
"writeConcern": {
93+
"w": 0
94+
}
95+
},
96+
"arguments": {
97+
"requests": [
98+
{
99+
"name": "deleteMany",
100+
"arguments": {
101+
"filter": {
102+
"_id": {
103+
"$lt": 3
104+
}
105+
},
106+
"hint": "_id_"
107+
}
108+
},
109+
{
110+
"name": "deleteMany",
111+
"arguments": {
112+
"filter": {
113+
"_id": {
114+
"$gte": 4
115+
}
116+
},
117+
"hint": {
118+
"_id": 1
119+
}
120+
}
121+
}
122+
],
123+
"options": {
124+
"ordered": true
125+
}
126+
},
127+
"error": true
128+
}
129+
],
130+
"expectations": [],
131+
"outcome": {
132+
"collection": {
133+
"data": [
134+
{
135+
"_id": 1,
136+
"x": 11
137+
},
138+
{
139+
"_id": 2,
140+
"x": 22
141+
},
142+
{
143+
"_id": 3,
144+
"x": 33
145+
},
146+
{
147+
"_id": 4,
148+
"x": 44
149+
}
150+
]
151+
}
152+
}
153+
}
154+
]
155+
}

0 commit comments

Comments
 (0)