Skip to content

Commit 2132e82

Browse files
Pass in all kwargs from PostgreSQLClient to the ConnectionPool
This allows for the py-utils developer to set any psql settings, such as max_idle.
1 parent bdbde85 commit 2132e82

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

src/nypl_py_utils/classes/postgresql_client.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ def __init__(self, host, port, db_name, user, password, **kwargs):
1919
'{db_name}').format(user=user, password=password,
2020
host=host, port=port,
2121
db_name=db_name)
22-
self.min_size = kwargs.get('min_size', 0)
23-
self.max_size = kwargs.get('max_size', 1)
24-
self.pool = ConnectionPool(
25-
self.conn_info, open=False,
26-
min_size=self.min_size, max_size=self.max_size)
22+
self.kwargs = kwargs
23+
self.kwargs['min_size'] = kwargs.get('min_size', 0)
24+
self.kwargs['max_size'] = kwargs.get('max_size', 1)
25+
self.pool = ConnectionPool(self.conn_info, open=False, **self.kwargs)
2726

2827
def connect(self):
2928
"""
@@ -34,8 +33,7 @@ def connect(self):
3433
try:
3534
if self.pool is None:
3635
self.pool = ConnectionPool(
37-
self.conn_info, open=False, min_size=self.min_size,
38-
max_size=self.max_size)
36+
self.conn_info, open=False, **self.kwargs)
3937
self.pool.open(wait=True, timeout=self.timeout)
4038
except psycopg.Error as e:
4139
self.logger.error(

tests/test_postgresql_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ def test_init(self, test_instance):
2424
def test_init_with_kwargs(self):
2525
test_instance = PostgreSQLClient(
2626
'test_host', 'test_port', 'test_db_name', 'test_user',
27-
'test_password', min_size=5, max_size=10)
27+
'test_password', min_size=5, max_size=10, max_idle=15.0)
2828
assert test_instance.pool.conninfo == (
2929
'postgresql://test_user:test_password@test_host:test_port/' +
3030
'test_db_name')
3131
assert test_instance.pool._opened is False
3232
assert test_instance.pool.min_size == 5
3333
assert test_instance.pool.max_size == 10
34+
assert test_instance.pool.max_idle == 15.0
3435

3536
def test_connect(self, test_instance):
3637
test_instance.connect()

0 commit comments

Comments
 (0)