Repository: incubator-airflow
Updated Branches:
  refs/heads/master 442575951 -> d642e38ec


[AIRFLOW-2581] RFLOW-2581] Fix DbApiHook autocommit

DbApiHook.run actually do not commit when I set to
autocommit=True
For example: hook.run(sql,autocommit=True)
This commit fixed this problem.

Closes #3482 from imroc/AIRFLOW-2581


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/d642e38e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/d642e38e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/d642e38e

Branch: refs/heads/master
Commit: d642e38ec7eac129739042e77f78b1dae4f2615e
Parents: 4425759
Author: roc <[email protected]>
Authored: Sat Jun 9 21:26:55 2018 +0200
Committer: Fokko Driesprong <[email protected]>
Committed: Sat Jun 9 21:26:55 2018 +0200

----------------------------------------------------------------------
 airflow/hooks/dbapi_hook.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/d642e38e/airflow/hooks/dbapi_hook.py
----------------------------------------------------------------------
diff --git a/airflow/hooks/dbapi_hook.py b/airflow/hooks/dbapi_hook.py
index 30a9b32..8f83077 100644
--- a/airflow/hooks/dbapi_hook.py
+++ b/airflow/hooks/dbapi_hook.py
@@ -137,7 +137,7 @@ class DbApiHook(BaseHook):
                     cur.execute(sql)
                 return cur.fetchone()
 
-    def run(self, sql, autocommit=False, parameters=None):
+    def run(self, sql, autocommit=True, parameters=None):
         """
         Runs a command or a list of commands. Pass a list of sql
         statements to the sql parameter to get them to execute
@@ -169,7 +169,9 @@ class DbApiHook(BaseHook):
                     else:
                         cur.execute(s)
 
-            if not getattr(conn, 'autocommit', False):
+            should_commit = getattr(conn, 'autocommit', False)
+
+            if should_commit:
                 conn.commit()
 
     def set_autocommit(self, conn, autocommit):

Reply via email to