Skip to content

Commit c5e09fc

Browse files
authored
Don't send routing context in HELLO message for direct connections (#515)
* Don't send routing context in HELLO message for direct connections * Remove unused attribute `routing_context` from Pool classes
1 parent ccfd4ab commit c5e09fc

9 files changed

+26
-30
lines changed

neo4j/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,4 @@ class CertificateConfigurationError(ConfigurationError):
308308

309309
class UnsupportedServerProduct(Exception):
310310
""" Raised when an unsupported server product is detected.
311-
"""
311+
"""

neo4j/io/__init__.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -560,33 +560,28 @@ def close(self):
560560
class BoltPool(IOPool):
561561

562562
@classmethod
563-
def open(cls, address, *, auth, pool_config, workspace_config, routing_context=None):
563+
def open(cls, address, *, auth, pool_config, workspace_config):
564564
"""Create a new BoltPool
565565
566566
:param address:
567567
:param auth:
568568
:param pool_config:
569569
:param workspace_config:
570-
:param routing_context:
571570
:return: BoltPool
572571
"""
573572

574-
if routing_context is None:
575-
routing_context = {}
576-
elif "address" in routing_context:
577-
raise ConfigurationError("The key 'address' is reserved for routing context.")
578-
routing_context["address"] = str(address)
579-
580573
def opener(addr, timeout):
581-
return Bolt.open(addr, auth=auth, timeout=timeout, routing_context=routing_context, **pool_config)
574+
return Bolt.open(
575+
addr, auth=auth, timeout=timeout, routing_context=None,
576+
**pool_config
577+
)
582578

583-
pool = cls(opener, pool_config, workspace_config, routing_context, address)
579+
pool = cls(opener, pool_config, workspace_config, address)
584580
return pool
585581

586-
def __init__(self, opener, pool_config, workspace_config, routing_context, address):
582+
def __init__(self, opener, pool_config, workspace_config, address):
587583
super(BoltPool, self).__init__(opener, pool_config, workspace_config)
588584
self.address = address
589-
self.routing_context = routing_context
590585

591586
def __repr__(self):
592587
return "<{} address={!r}>".format(self.__class__.__name__, self.address)
@@ -621,26 +616,25 @@ def open(cls, *addresses, auth, pool_config, workspace_config, routing_context=N
621616
routing_context["address"] = str(address)
622617

623618
def opener(addr, timeout):
624-
return Bolt.open(addr, auth=auth, timeout=timeout, routing_context=routing_context, **pool_config)
619+
return Bolt.open(addr, auth=auth, timeout=timeout,
620+
routing_context=routing_context, **pool_config)
625621

626-
pool = cls(opener, pool_config, workspace_config, routing_context, address)
622+
pool = cls(opener, pool_config, workspace_config, address)
627623
return pool
628624

629-
def __init__(self, opener, pool_config, workspace_config, routing_context, address):
625+
def __init__(self, opener, pool_config, workspace_config, address):
630626
"""
631627
632628
:param opener:
633629
:param pool_config:
634630
:param workspace_config:
635-
:param routing_context: Dictionary with routing information
636631
:param addresses:
637632
"""
638633
super(Neo4jPool, self).__init__(opener, pool_config, workspace_config)
639634
# Each database have a routing table, the default database is a special case.
640635
log.debug("[#0000] C: <NEO4J POOL> routing address %r", address)
641636
self.address = address
642637
self.routing_tables = {workspace_config.database: RoutingTable(database=workspace_config.database, routers=[address])}
643-
self.routing_context = routing_context
644638
self.refresh_lock = Lock()
645639

646640
def __repr__(self):

neo4j/io/_bolt4.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,12 @@ def get_base_headers(self):
490490
enables server-side routing to propagate the same behaviour
491491
through its driver.
492492
"""
493-
return {
493+
headers = {
494494
"user_agent": self.user_agent,
495-
"routing": self.routing_context,
496495
}
496+
if self.routing_context is not None:
497+
headers["routing"] = self.routing_context
498+
return headers
497499

498500

499501
class Bolt4x2(Bolt4x1):
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
!: BOLT 4.1
22
!: PORT 9001
33

4-
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
4+
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
55
S: SUCCESS {"server": "Neo4j/4.1.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
66
C: GOODBYE
7-
S: <EXIT>
7+
S: <EXIT>

tests/stub/scripts/v4x1/return_1_noop_port_9001.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
!: AUTO RESET
44
!: PORT 9001
55

6-
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
6+
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
77
S: SUCCESS {"server": "Neo4j/4.1.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
88
C: RUN "RETURN 1 AS x" {} {"mode": "r"}
99
PULL {"n": 2}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
!: BOLT 4.1
22
!: PORT 9001
33

4-
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
4+
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
55
S: SUCCESS {"server": "Bogus/4.1.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
66
C: RUN "RETURN 1 AS x" {} {"mode": "r"}
77
PULL {"n": -1}
88
S: SUCCESS {"fields": ["x"]}
99
RECORD [1]
10-
SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"}
10+
SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
!: BOLT 4.2
22
!: PORT 9001
33

4-
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
4+
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
55
S: SUCCESS {"server": "Neo4j/4.2.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
66
C: GOODBYE
7-
S: <EXIT>
7+
S: <EXIT>

tests/stub/scripts/v4x2/return_1_noop_port_9001.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
!: AUTO RESET
44
!: PORT 9001
55

6-
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
6+
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
77
S: SUCCESS {"server": "Neo4j/4.2.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
88
C: RUN "RETURN 1 AS x" {} {"mode": "r"}
99
PULL {"n": 2}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
!: BOLT 4.2
22
!: PORT 9001
33

4-
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}}
4+
C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"}
55
S: SUCCESS {"server": "Bogus/4.2.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"}
66
C: RUN "RETURN 1 AS x" {} {"mode": "r"}
77
PULL {"n": -1}
88
S: SUCCESS {"fields": ["x"]}
99
RECORD [1]
10-
SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"}
10+
SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"}

0 commit comments

Comments
 (0)