fordguo closed pull request #2227: [AIRFLOW-1083] Fixes the connect error when jaydebeapi >1.0 and the jdbc's autocommit bug URL: https://github.com/apache/incubator-airflow/pull/2227
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/airflow/hooks/jdbc_hook.py b/airflow/hooks/jdbc_hook.py index bc1f352ecc..4d51dd306c 100644 --- a/airflow/hooks/jdbc_hook.py +++ b/airflow/hooks/jdbc_hook.py @@ -44,6 +44,9 @@ class JdbcHook(DbApiHook): default_conn_name = 'jdbc_default' supports_autocommit = True + def is_jaydebeapi_v1(self): + return jaydebeapi.__version_info__[0] >= 1 + def get_conn(self): conn = self.get_connection(getattr(self, self.conn_name_attr)) host = conn.host @@ -52,9 +55,15 @@ def get_conn(self): jdbc_driver_loc = conn.extra_dejson.get('extra__jdbc__drv_path') jdbc_driver_name = conn.extra_dejson.get('extra__jdbc__drv_clsname') - conn = jaydebeapi.connect(jdbc_driver_name, - [str(host), str(login), str(psw)], - jdbc_driver_loc,) + if self.is_jaydebeapi_v1(): + conn = jaydebeapi.connect(jdbc_driver_name, + str(host), + [str(login), str(psw)], + jdbc_driver_loc,) + else: + conn = jaydebeapi.connect(jdbc_driver_name, + [str(host), str(login), str(psw)], + jdbc_driver_loc,) return conn def set_autocommit(self, conn, autocommit): @@ -64,4 +73,7 @@ def set_autocommit(self, conn, autocommit): :param conn: The connection :return: """ - conn.jconn.autocommit = autocommit + if self.is_jaydebeapi_v1(): + conn.jconn.autoCommit = autocommit + else: + conn.jconn.autocommit = autocommit ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services