Skip to content

Commit 6932d25

Browse files
committed
PYTHON-2253 raise client-side error when allowDiskUse is specified with MongoDB <= 3.2
1 parent 0743c0b commit 6932d25

File tree

5 files changed

+109
-4
lines changed

5 files changed

+109
-4
lines changed

pymongo/collection.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,8 @@ def find(self, *args, **kwargs):
14421442
disk files to store data exceeding the system memory limit while
14431443
processing a blocking sort operation. The option has no effect if
14441444
MongoDB can satisfy the specified sort using an index, or if the
1445-
blocking sort requires less memory than the 100 MiB limit.
1445+
blocking sort requires less memory than the 100 MiB limit. This
1446+
option is only supported on MongoDB 4.4 and above.
14461447
14471448
.. note:: There are a number of caveats to using
14481449
:attr:`~pymongo.cursor.CursorType.EXHAUST` as cursor_type:

pymongo/cursor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ def allow_disk_use(self, allow_disk_use):
441441
"""Specifies whether MongoDB can use temporary disk files while
442442
processing a blocking sort operation.
443443
444-
Raises :exc:`TypeError` is `allow_disk_use` is not a boolean.
444+
Raises :exc:`TypeError` if `allow_disk_use` is not a boolean.
445+
446+
.. note:: `allow_disk_use` requires server version **>= 4.4**
445447
446448
:Parameters:
447449
- `allow_disk_use`: if True, MongoDB may use temporary

pymongo/message.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,9 @@ def use_command(self, sock_info, exhaust):
283283
'version of %d.' % (sock_info.max_wire_version,))
284284

285285
if sock_info.max_wire_version < 4 and self.allow_disk_use is not None:
286-
# Ignore allowDiskUse for MongoDB < 3.2.
287-
self.allow_disk_use = None
286+
raise ConfigurationError(
287+
'Specifying allowDiskUse is unsupported with a max wire '
288+
'version of %d.' % (sock_info.max_wire_version,))
288289

289290
sock_info.validate_session(self.client, self.session)
290291

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"runOn": [
3+
{
4+
"maxServerVersion": "3.0.99"
5+
}
6+
],
7+
"collection_name": "test_find_allowdiskuse_clienterror",
8+
"tests": [
9+
{
10+
"description": "Find fails when allowDiskUse true is specified against pre 3.2 server",
11+
"operations": [
12+
{
13+
"object": "collection",
14+
"name": "find",
15+
"arguments": {
16+
"filter": {},
17+
"allowDiskUse": true
18+
},
19+
"error": true
20+
}
21+
],
22+
"expectations": []
23+
},
24+
{
25+
"description": "Find fails when allowDiskUse false is specified against pre 3.2 server",
26+
"operations": [
27+
{
28+
"object": "collection",
29+
"name": "find",
30+
"arguments": {
31+
"filter": {},
32+
"allowDiskUse": false
33+
},
34+
"error": true
35+
}
36+
],
37+
"expectations": []
38+
}
39+
]
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "3.2",
5+
"maxServerVersion": "4.3.0"
6+
}
7+
],
8+
"collection_name": "test_find_allowdiskuse_servererror",
9+
"tests": [
10+
{
11+
"description": "Find fails when allowDiskUse true is specified against pre 4.4 server (server-side error)",
12+
"operations": [
13+
{
14+
"object": "collection",
15+
"name": "find",
16+
"arguments": {
17+
"filter": {},
18+
"allowDiskUse": true
19+
},
20+
"error": true
21+
}
22+
],
23+
"expectations": [
24+
{
25+
"command_started_event": {
26+
"command": {
27+
"find": "test_find_allowdiskuse_servererror",
28+
"filter": {},
29+
"allowDiskUse": true
30+
}
31+
}
32+
}
33+
]
34+
},
35+
{
36+
"description": "Find fails when allowDiskUse false is specified against pre 4.4 server (server-side error)",
37+
"operations": [
38+
{
39+
"object": "collection",
40+
"name": "find",
41+
"arguments": {
42+
"filter": {},
43+
"allowDiskUse": false
44+
},
45+
"error": true
46+
}
47+
],
48+
"expectations": [
49+
{
50+
"command_started_event": {
51+
"command": {
52+
"find": "test_find_allowdiskuse_servererror",
53+
"filter": {},
54+
"allowDiskUse": false
55+
}
56+
}
57+
}
58+
]
59+
}
60+
]
61+
}

0 commit comments

Comments
 (0)