sql: only consider known valid connection parameters (#17143)

This commit is contained in:
Frédéric Péters 2017-06-23 09:51:46 +02:00
parent 03493c73c0
commit d73542e727
1 changed files with 4 additions and 3 deletions

View File

@ -240,9 +240,10 @@ def get_connection(new=False):
cleanup_connection()
if not hasattr(get_publisher(), 'pgconn') or get_publisher().pgconn is None:
postgresql_cfg = {}
for k, v in get_cfg('postgresql', {}).items():
if v and isinstance(v, basestring):
postgresql_cfg[k] = v
for param in ('database', 'user', 'password', 'host', 'port'):
value = get_cfg('postgresql', {}).get(param)
if value:
postgresql_cfg[param] = value
try:
get_publisher().pgconn = psycopg2.connect(**postgresql_cfg)
except psycopg2.Error: