Skip to content

Commit 8d8d95d

Browse files
committed
Fix protocol negotiation for 4.0 servers
1 parent 180d972 commit 8d8d95d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

neo4j/io/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,23 +239,24 @@ def version_list(cls, versions, limit=4):
239239
returned is limited to four.
240240
"""
241241
ranges_supported = versions[0] >= Version(4, 3)
242+
without_changes = {Version(4, 2)}
242243
if versions and ranges_supported:
243244
start, end = 0, 0
244245
first_major = versions[start][0]
245246
minors = []
246-
for end, version in enumerate(versions):
247+
for version in versions:
247248
if version[0] == first_major:
248249
minors.append(version[1])
249250
else:
250251
break
251-
new_versions = ([Version(first_major, minors)] + versions[1:end])[:(limit - 1)]
252-
try:
253-
new_versions.append(versions[end])
254-
except IndexError:
255-
pass
256-
return new_versions
252+
new_versions = [
253+
Version(first_major, minors),
254+
*(v for v in versions[1:] if v not in without_changes)
255+
]
257256
else:
258-
return versions[:limit]
257+
new_versions = [v for v in versions if v not in without_changes]
258+
new_versions = [*new_versions[:(limit - 1)], versions[-1]]
259+
return new_versions
259260

260261
@classmethod
261262
def get_handshake(cls):

tests/unit/io/test_class_bolt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_class_method_protocol_handlers_with_invalid_protocol_version():
5353
def test_class_method_get_handshake():
5454
# python -m pytest tests/unit/io/test_class_bolt.py -s -v -k test_class_method_get_handshake
5555
handshake = Bolt.get_handshake()
56-
assert handshake == b"\x00\x03\x03\x04\x00\x00\x02\x04\x00\x00\x01\x04\x00\x00\x00\x03"
56+
assert handshake == b"\x00\x03\x03\x04\x00\x00\x01\x04\x00\x00\x00\x04\x00\x00\x00\x03"
5757

5858

5959
def test_magic_preamble():

0 commit comments

Comments
 (0)