Skip to content

Commit 06de216

Browse files
committed
Acquire RT without impersonated user if possible
This is an optimization saving a few bytes over the wire. When there is an explicit database configured for a session, there is no need to send the impersonated user along with the `ROUTE` request. The only difference this would make is that insufficient permissions would be noticed when fetching the RT instead of when performing any actual action on the session. Since routing is part of the global driver/pool operations and not coupled to sessions, doing it this way seems like the logical conclusion.
1 parent 793f360 commit 06de216

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

neo4j/io/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -711,13 +711,12 @@ def time_remaining():
711711
"within {!r}s".format(timeout))
712712

713713
def acquire(self, access_mode=None, timeout=None, database=None,
714-
imp_user=None, bookmarks=None):
714+
bookmarks=None):
715715
""" Acquire a connection to a server that can satisfy a set of parameters.
716716
717717
:param access_mode:
718718
:param timeout:
719719
:param database:
720-
:param imp_user:
721720
:param bookmarks:
722721
"""
723722

@@ -1152,7 +1151,7 @@ def ensure_routing_table_is_fresh(self, *, access_mode, database, imp_user,
11521151

11531152
return True
11541153

1155-
def _select_address(self, *, access_mode, database, imp_user, bookmarks):
1154+
def _select_address(self, *, access_mode, database):
11561155
from neo4j.api import READ_ACCESS
11571156
""" Selects the address with the fewest in-use connections.
11581157
"""
@@ -1178,29 +1177,29 @@ def _select_address(self, *, access_mode, database, imp_user, bookmarks):
11781177
return choice(addresses_by_usage[min(addresses_by_usage)])
11791178

11801179
def acquire(self, access_mode=None, timeout=None, database=None,
1181-
imp_user=None, bookmarks=None):
1180+
bookmarks=None):
11821181
if access_mode not in (WRITE_ACCESS, READ_ACCESS):
11831182
raise ClientError("Non valid 'access_mode'; {}".format(access_mode))
11841183
if not timeout:
1185-
raise ClientError("'timeout' must be a float larger than 0; {}".format(timeout))
1184+
raise ClientError("'timeout' must be a float larger than 0; {}"
1185+
.format(timeout))
11861186

11871187
from neo4j.api import check_access_mode
11881188
access_mode = check_access_mode(access_mode)
11891189
with self.refresh_lock:
11901190
log.debug("[#0000] C: <ROUTING TABLE ENSURE FRESH> %r",
11911191
self.routing_tables)
11921192
self.ensure_routing_table_is_fresh(
1193-
access_mode=access_mode, database=database, imp_user=imp_user,
1193+
access_mode=access_mode, database=database, imp_user=None,
11941194
bookmarks=bookmarks
11951195
)
11961196

11971197
while True:
11981198
try:
1199-
# Get an address for a connection that have the fewest in-use connections.
1200-
address = self._select_address(
1201-
access_mode=access_mode, database=database,
1202-
imp_user=imp_user, bookmarks=bookmarks
1203-
)
1199+
# Get an address for a connection that have the fewest in-use
1200+
# connections.
1201+
address = self._select_address(access_mode=access_mode,
1202+
database=database)
12041203
except (ReadServiceUnavailable, WriteServiceUnavailable) as err:
12051204
raise SessionExpired("Failed to obtain connection towards '%s' server." % access_mode) from err
12061205
try:

neo4j/work/simple.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def _connect(self, access_mode):
144144
access_mode=access_mode,
145145
timeout=self._config.connection_acquisition_timeout,
146146
database=self._config.database,
147-
imp_user=self._config.impersonated_user,
148147
bookmarks=self._bookmarks
149148
)
150149

tests/unit/io/test_direct.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def opener(addr, timeout):
104104
super().__init__(opener, self.pool_config, self.workspace_config)
105105
self.address = address
106106

107-
def acquire(self, access_mode=None, timeout=None, database=None,
108-
imp_user=None):
107+
def acquire(self, access_mode=None, timeout=None, database=None):
109108
return self._acquire(self.address, timeout)
110109

111110

tests/unit/test_driver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ def test_driver_opens_write_session_by_default(uri, mocker):
137137
access_mode=WRITE_ACCESS,
138138
timeout=mocker.ANY,
139139
database=mocker.ANY,
140-
imp_user=mocker.ANY,
141140
bookmarks=mocker.ANY
142141
)
143142
tx_begin_mock.assert_called_once_with(

0 commit comments

Comments
 (0)