[AIRFLOW-2364] Warn when setting autocommit on a connection which does not support it
Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/a33b29c8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/a33b29c8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/a33b29c8 Branch: refs/heads/master Commit: a33b29c8512c599b97e53808ebf796039a89c15c Parents: 3450f52 Author: Arthur Wiedmer <[email protected]> Authored: Mon Apr 23 09:42:13 2018 -0700 Committer: Arthur Wiedmer <[email protected]> Committed: Mon Apr 23 09:52:08 2018 -0700 ---------------------------------------------------------------------- airflow/hooks/dbapi_hook.py | 8 ++++++++ 1 file changed, 8 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/a33b29c8/airflow/hooks/dbapi_hook.py ---------------------------------------------------------------------- diff --git a/airflow/hooks/dbapi_hook.py b/airflow/hooks/dbapi_hook.py index b6cdff6..25b1588 100644 --- a/airflow/hooks/dbapi_hook.py +++ b/airflow/hooks/dbapi_hook.py @@ -173,6 +173,14 @@ class DbApiHook(BaseHook): conn.commit() def set_autocommit(self, conn, autocommit): + """ + Sets the autocommit flag on the connection + """ + if not self.supports_autocommit and autocommit: + self.log.warn( + ("%s connection doesn't support " + "autocommit but autocommit activated."), + getattr(self, self.conn_name_attr)) conn.autocommit = autocommit def get_cursor(self):
