Skip to content

Commit b878ed6

Browse files
committed
PYTHON-1409 - Improve server compatibility error messages
1 parent 49cee29 commit b878ed6

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

pymongo/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
MAX_WRITE_BATCH_SIZE = 1000
4949

5050
# What this version of PyMongo supports.
51+
MIN_SUPPORTED_SERVER_VERSION = "2.6"
5152
MIN_SUPPORTED_WIRE_VERSION = 2
5253
MAX_SUPPORTED_WIRE_VERSION = 5
5354

pymongo/topology_description.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,21 @@ def __init__(self,
7676
s.max_wire_version is not None
7777
and s.max_wire_version < common.MIN_SUPPORTED_WIRE_VERSION)
7878

79-
if server_too_new or server_too_old:
79+
if server_too_new:
8080
self._incompatible_err = (
81-
"Server at %s:%d "
82-
"uses wire protocol versions %d through %d, "
83-
"but PyMongo only supports %d through %d"
81+
"Server at %s:%d requires wire version %d, but this "
82+
"version of PyMongo only supports up to %d."
8483
% (s.address[0], s.address[1],
85-
s.min_wire_version, s.max_wire_version,
84+
s.min_wire_version, common.MAX_SUPPORTED_WIRE_VERSION))
85+
86+
elif server_too_old:
87+
self._incompatible_err = (
88+
"Server at %s:%d reports wire version %d, but this "
89+
"version of PyMongo requires at least %d (MongoDB %s)."
90+
% (s.address[0], s.address[1],
91+
s.max_wire_version,
8692
common.MIN_SUPPORTED_WIRE_VERSION,
87-
common.MAX_SUPPORTED_WIRE_VERSION))
93+
common.MIN_SUPPORTED_SERVER_VERSION))
8894

8995
break
9096

test/test_topology.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,33 @@ def test_wire_version(self):
567567
t.select_servers(any_server_selector)
568568
except ConfigurationError as e:
569569
# Error message should say which server failed and why.
570-
self.assertTrue('a:27017' in str(e))
571-
self.assertTrue('wire protocol versions 11 through 12' in str(e))
570+
self.assertEqual(
571+
str(e),
572+
"Server at a:27017 requires wire version 11, but this version "
573+
"of PyMongo only supports up to %d."
574+
% (common.MAX_SUPPORTED_WIRE_VERSION,))
575+
else:
576+
self.fail('No error with incompatible wire version')
577+
578+
# Incompatible.
579+
got_ismaster(t, address, {
580+
'ok': 1,
581+
'ismaster': True,
582+
'setName': 'rs',
583+
'hosts': ['a'],
584+
'minWireVersion': 0,
585+
'maxWireVersion': 0})
586+
587+
try:
588+
t.select_servers(any_server_selector)
589+
except ConfigurationError as e:
590+
# Error message should say which server failed and why.
591+
self.assertEqual(
592+
str(e),
593+
"Server at a:27017 reports wire version 0, but this version "
594+
"of PyMongo requires at least %d (MongoDB %s)."
595+
% (common.MIN_SUPPORTED_WIRE_VERSION,
596+
common.MIN_SUPPORTED_SERVER_VERSION))
572597
else:
573598
self.fail('No error with incompatible wire version')
574599

0 commit comments

Comments
 (0)