Skip to content

Commit 8d03ae2

Browse files
Fix host translation issue on direct class to dj.Connection.
1 parent aa1b563 commit 8d03ae2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

datajoint/connection.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ def conn(host=None, user=None, password=None, *, init_fun=None, reset=False, use
107107
#encrypted-connection-options).
108108
"""
109109
if not hasattr(conn, 'connection') or reset:
110-
host_input = host if host is not None else config['database.host']
111-
host = get_host_hook(host_input)
110+
host = host if host is not None else config['database.host']
112111
user = user if user is not None else config['database.user']
113112
password = password if password is not None else config['database.password']
114113
if user is None: # pragma: no cover
@@ -117,8 +116,7 @@ def conn(host=None, user=None, password=None, *, init_fun=None, reset=False, use
117116
password = getpass(prompt="Please enter DataJoint password: ")
118117
init_fun = init_fun if init_fun is not None else config['connection.init_function']
119118
use_tls = use_tls if use_tls is not None else config['database.use_tls']
120-
conn.connection = Connection(host, user, password, None, init_fun, use_tls,
121-
host_input=host_input)
119+
conn.connection = Connection(host, user, password, None, init_fun, use_tls)
122120
return conn.connection
123121

124122

@@ -160,8 +158,8 @@ class Connection:
160158
:param use_tls: TLS encryption option
161159
"""
162160

163-
def __init__(self, host, user, password, port=None, init_fun=None, use_tls=None,
164-
host_input=None):
161+
def __init__(self, host, user, password, port=None, init_fun=None, use_tls=None):
162+
host_input, host = (host, get_host_hook(host))
165163
if ':' in host:
166164
# the port in the hostname overrides the port argument
167165
host, port = host.split(':')

tests/test_connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ def test_dj_conn():
1717
assert_true(c.is_connected)
1818

1919

20+
def test_dj_connection_class():
21+
"""
22+
Should be able to establish a connection
23+
"""
24+
c = dj.Connection(**CONN_INFO)
25+
assert_true(c.is_connected)
26+
27+
2028
def test_persistent_dj_conn():
2129
"""
2230
conn() method should provide persistent connection across calls.

0 commit comments

Comments
 (0)