diff --git a/neo4j/exceptions.py b/neo4j/exceptions.py index 5771b5b8..de584a97 100644 --- a/neo4j/exceptions.py +++ b/neo4j/exceptions.py @@ -308,4 +308,4 @@ class CertificateConfigurationError(ConfigurationError): class UnsupportedServerProduct(Exception): """ Raised when an unsupported server product is detected. - """ \ No newline at end of file + """ diff --git a/neo4j/io/__init__.py b/neo4j/io/__init__.py index 934cf492..bce50b0f 100644 --- a/neo4j/io/__init__.py +++ b/neo4j/io/__init__.py @@ -560,33 +560,28 @@ def close(self): class BoltPool(IOPool): @classmethod - def open(cls, address, *, auth, pool_config, workspace_config, routing_context=None): + def open(cls, address, *, auth, pool_config, workspace_config): """Create a new BoltPool :param address: :param auth: :param pool_config: :param workspace_config: - :param routing_context: :return: BoltPool """ - if routing_context is None: - routing_context = {} - elif "address" in routing_context: - raise ConfigurationError("The key 'address' is reserved for routing context.") - routing_context["address"] = str(address) - def opener(addr, timeout): - return Bolt.open(addr, auth=auth, timeout=timeout, routing_context=routing_context, **pool_config) + return Bolt.open( + addr, auth=auth, timeout=timeout, routing_context=None, + **pool_config + ) - pool = cls(opener, pool_config, workspace_config, routing_context, address) + pool = cls(opener, pool_config, workspace_config, address) return pool - def __init__(self, opener, pool_config, workspace_config, routing_context, address): + def __init__(self, opener, pool_config, workspace_config, address): super(BoltPool, self).__init__(opener, pool_config, workspace_config) self.address = address - self.routing_context = routing_context def __repr__(self): return "<{} address={!r}>".format(self.__class__.__name__, self.address) @@ -621,18 +616,18 @@ def open(cls, *addresses, auth, pool_config, workspace_config, routing_context=N routing_context["address"] = str(address) def opener(addr, timeout): - return Bolt.open(addr, auth=auth, timeout=timeout, routing_context=routing_context, **pool_config) + return Bolt.open(addr, auth=auth, timeout=timeout, + routing_context=routing_context, **pool_config) - pool = cls(opener, pool_config, workspace_config, routing_context, address) + pool = cls(opener, pool_config, workspace_config, address) return pool - def __init__(self, opener, pool_config, workspace_config, routing_context, address): + def __init__(self, opener, pool_config, workspace_config, address): """ :param opener: :param pool_config: :param workspace_config: - :param routing_context: Dictionary with routing information :param addresses: """ super(Neo4jPool, self).__init__(opener, pool_config, workspace_config) @@ -640,7 +635,6 @@ def __init__(self, opener, pool_config, workspace_config, routing_context, addre log.debug("[#0000] C: routing address %r", address) self.address = address self.routing_tables = {workspace_config.database: RoutingTable(database=workspace_config.database, routers=[address])} - self.routing_context = routing_context self.refresh_lock = Lock() def __repr__(self): diff --git a/neo4j/io/_bolt4.py b/neo4j/io/_bolt4.py index e305a157..d691c796 100644 --- a/neo4j/io/_bolt4.py +++ b/neo4j/io/_bolt4.py @@ -490,10 +490,12 @@ def get_base_headers(self): enables server-side routing to propagate the same behaviour through its driver. """ - return { + headers = { "user_agent": self.user_agent, - "routing": self.routing_context, } + if self.routing_context is not None: + headers["routing"] = self.routing_context + return headers class Bolt4x2(Bolt4x1): diff --git a/tests/stub/scripts/v4x1/empty_explicit_hello_goodbye.script b/tests/stub/scripts/v4x1/empty_explicit_hello_goodbye.script index 20043c9a..30497921 100644 --- a/tests/stub/scripts/v4x1/empty_explicit_hello_goodbye.script +++ b/tests/stub/scripts/v4x1/empty_explicit_hello_goodbye.script @@ -1,7 +1,7 @@ !: BOLT 4.1 !: PORT 9001 -C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}} +C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Neo4j/4.1.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"} C: GOODBYE -S: \ No newline at end of file +S: diff --git a/tests/stub/scripts/v4x1/return_1_noop_port_9001.script b/tests/stub/scripts/v4x1/return_1_noop_port_9001.script index 2d0f5263..41e5f171 100644 --- a/tests/stub/scripts/v4x1/return_1_noop_port_9001.script +++ b/tests/stub/scripts/v4x1/return_1_noop_port_9001.script @@ -3,7 +3,7 @@ !: AUTO RESET !: PORT 9001 -C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}} +C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Neo4j/4.1.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"} C: RUN "RETURN 1 AS x" {} {"mode": "r"} PULL {"n": 2} diff --git a/tests/stub/scripts/v4x1/return_1_port_9001_bogus_server.script b/tests/stub/scripts/v4x1/return_1_port_9001_bogus_server.script index 5332d73a..a41b8dab 100644 --- a/tests/stub/scripts/v4x1/return_1_port_9001_bogus_server.script +++ b/tests/stub/scripts/v4x1/return_1_port_9001_bogus_server.script @@ -1,10 +1,10 @@ !: BOLT 4.1 !: PORT 9001 -C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}} +C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Bogus/4.1.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"} C: RUN "RETURN 1 AS x" {} {"mode": "r"} PULL {"n": -1} S: SUCCESS {"fields": ["x"]} RECORD [1] - SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"} \ No newline at end of file + SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"} diff --git a/tests/stub/scripts/v4x2/empty_explicit_hello_goodbye.script b/tests/stub/scripts/v4x2/empty_explicit_hello_goodbye.script index ec518ae5..efd6f6cd 100644 --- a/tests/stub/scripts/v4x2/empty_explicit_hello_goodbye.script +++ b/tests/stub/scripts/v4x2/empty_explicit_hello_goodbye.script @@ -1,7 +1,7 @@ !: BOLT 4.2 !: PORT 9001 -C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}} +C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Neo4j/4.2.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"} C: GOODBYE -S: \ No newline at end of file +S: diff --git a/tests/stub/scripts/v4x2/return_1_noop_port_9001.script b/tests/stub/scripts/v4x2/return_1_noop_port_9001.script index 23fe647c..c9335e53 100644 --- a/tests/stub/scripts/v4x2/return_1_noop_port_9001.script +++ b/tests/stub/scripts/v4x2/return_1_noop_port_9001.script @@ -3,7 +3,7 @@ !: AUTO RESET !: PORT 9001 -C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}} +C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Neo4j/4.2.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"} C: RUN "RETURN 1 AS x" {} {"mode": "r"} PULL {"n": 2} diff --git a/tests/stub/scripts/v4x2/return_1_port_9001_bogus_server.script b/tests/stub/scripts/v4x2/return_1_port_9001_bogus_server.script index cfc502cc..801a86fd 100644 --- a/tests/stub/scripts/v4x2/return_1_port_9001_bogus_server.script +++ b/tests/stub/scripts/v4x2/return_1_port_9001_bogus_server.script @@ -1,10 +1,10 @@ !: BOLT 4.2 !: PORT 9001 -C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test", "routing": {"address": "localhost:9001"}} +C: HELLO {"user_agent": "test", "scheme": "basic", "principal": "test", "credentials": "test"} S: SUCCESS {"server": "Bogus/4.2.0", "connection_id": "123e4567-e89b-12d3-a456-426655440000"} C: RUN "RETURN 1 AS x" {} {"mode": "r"} PULL {"n": -1} S: SUCCESS {"fields": ["x"]} RECORD [1] - SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"} \ No newline at end of file + SUCCESS {"bookmark": "neo4j:bookmark-test-1", "type": "r", "t_last": 5, "db": "neo4j"}