Skip to content

Commit

Permalink
Fix client construction with round_robin #373
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Apr 26, 2023
1 parent 84b5113 commit 5f2707a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
14 changes: 10 additions & 4 deletions clickhouse_driver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,19 @@ def __init__(self, *args, **kwargs):
url = urlparse('clickhouse://' + host)

connection_kwargs = kwargs.copy()
if len(args) > 2:
# port as positional argument
num_args = len(args)
if num_args >= 2:
# host and port as positional arguments
connection_args = (url.hostname, url.port) + args[2:]
else:
# port as keyword argument
elif num_args >= 1:
# host as positional and port as keyword argument
connection_args = (url.hostname, ) + args[1:]
connection_kwargs['port'] = url.port
else:
# host and port as keyword arguments
connection_args = tuple()
connection_kwargs['host'] = url.hostname
connection_kwargs['port'] = url.port

connection = Connection(*connection_args, **connection_kwargs)
self.connections.append(connection)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,31 @@ def test_round_robin(self):
self.assertFalse(client.connection.connected)
self.assertFalse(list(client.connections)[0].connected)

def test_round_robin_client_construction(self):
# host and port as keyword args
Client(
host='host',
port=9000,
round_robin=True,
alt_hosts='host2'
)

# host as positional and port as keyword arg
Client(
'host',
9000,
round_robin=True,
alt_hosts='host2'
)

# host and port as positional args
Client(
'host',
9000,
round_robin=True,
alt_hosts='host2'
)

def test_tcp_keepalive(self):
self.assertFalse(self.client.connection.tcp_keepalive)

Expand Down

0 comments on commit 5f2707a

Please sign in to comment.