This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new f248a21  Remove duplicate code on dbapi hook (#18821)
f248a21 is described below

commit f248a215aa341608e2bc7d9083ca9d18ab756ac4
Author: Mario Taddeucci <[email protected]>
AuthorDate: Sat Oct 9 10:59:02 2021 -0300

    Remove duplicate code on dbapi hook (#18821)
---
 airflow/hooks/dbapi.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/airflow/hooks/dbapi.py b/airflow/hooks/dbapi.py
index 3c51e6f..b23d052 100644
--- a/airflow/hooks/dbapi.py
+++ b/airflow/hooks/dbapi.py
@@ -377,12 +377,9 @@ class DbApiHook(BaseHook):
         """Tests the connection by executing a select 1 query"""
         status, message = False, ''
         try:
-            with closing(self.get_conn()) as conn:
-                with closing(conn.cursor()) as cur:
-                    cur.execute("select 1")
-                    if cur.fetchone():
-                        status = True
-                        message = 'Connection successfully tested'
+            if self.get_first("select 1"):
+                status = True
+                message = 'Connection successfully tested'
         except Exception as e:
             status = False
             message = str(e)

Reply via email to