[AIRFLOW-941] Use defined parameters for psycopg2 This works around https://github.com/psycopg/psycopg2/issues/517 .
Closes #2126 from bolkedebruin/AIRFLOW-941 Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/1f3aead5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/1f3aead5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/1f3aead5 Branch: refs/heads/v1-8-test Commit: 1f3aead5c486c3576a5df3b6904aa449b8a1d90a Parents: 4077c6d Author: Bolke de Bruin <[email protected]> Authored: Mon Mar 6 21:03:14 2017 +0100 Committer: Bolke de Bruin <[email protected]> Committed: Sun Mar 12 08:28:48 2017 -0700 ---------------------------------------------------------------------- airflow/hooks/postgres_hook.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/1f3aead5/airflow/hooks/postgres_hook.py ---------------------------------------------------------------------- diff --git a/airflow/hooks/postgres_hook.py b/airflow/hooks/postgres_hook.py index 75c8226..750ebbb 100644 --- a/airflow/hooks/postgres_hook.py +++ b/airflow/hooks/postgres_hook.py @@ -32,10 +32,17 @@ class PostgresHook(DbApiHook): conn = self.get_connection(self.postgres_conn_id) conn_args = dict( host=conn.host, - user=conn.login, - password=conn.password, - dbname=conn.schema, - port=conn.port) + dbname=self.schema or conn.schema) + # work around for https://github.com/psycopg/psycopg2/issues/517 + # todo: remove when psycopg2 2.7.1 is released + # https://issues.apache.org/jira/browse/AIRFLOW-945 + if conn.port: + conn_args['port'] = conn.port + if conn.login: + conn_args['user'] = conn.login + if conn.password: + conn_args['password'] = conn.password + # check for ssl parameters in conn.extra for arg_name, arg_val in conn.extra_dejson.items(): if arg_name in ['sslmode', 'sslcert', 'sslkey', 'sslrootcert', 'sslcrl', 'application_name']:
