Repository: incubator-airflow
Updated Branches:
  refs/heads/v1-8-test 180ef35c0 -> 5212665ff


[AIRFLOW-822] Close db before exception

The basehook contains functionality to retrieve
connections from the
database. If a connection does not exist it will
throw an exception.
This exception will be thrown before the
connection to the database
is closed. Therefore the session to the db might
stay open and linger.

Closes #2038 from Fokko/airflow-822

(cherry picked from commit 4b6c389b34d0496c8dde86d9b6e5625a53edd93d)
Signed-off-by: Bolke de Bruin <[email protected]>


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

Branch: refs/heads/v1-8-test
Commit: 5212665fff535ebebb1ce75b2904a7ec1ca42797
Parents: 180ef35
Author: Fokko Driesprong <[email protected]>
Authored: Tue Jan 31 14:34:01 2017 +0100
Committer: Bolke de Bruin <[email protected]>
Committed: Tue Jan 31 14:35:01 2017 +0100

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


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/5212665f/airflow/hooks/base_hook.py
----------------------------------------------------------------------
diff --git a/airflow/hooks/base_hook.py b/airflow/hooks/base_hook.py
index e640b63..f5eeb6a 100644
--- a/airflow/hooks/base_hook.py
+++ b/airflow/hooks/base_hook.py
@@ -48,11 +48,11 @@ class BaseHook(object):
             .filter(Connection.conn_id == conn_id)
             .all()
         )
+        session.expunge_all()
+        session.close()
         if not db:
             raise AirflowException(
                 "The conn_id `{0}` isn't defined".format(conn_id))
-        session.expunge_all()
-        session.close()
         return db
 
     @classmethod

Reply via email to