You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2019/06/01 01:28:20 UTC

[incubator-superset] 06/13: [testconn] Explicit closing engine connection (#7570)

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

michellet pushed a commit to branch release--0.33
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git

commit ad37673609bf216af58f64cafe9bf3dda566b2f7
Author: John Bodley <45...@users.noreply.github.com>
AuthorDate: Wed May 22 09:42:03 2019 -0700

    [testconn] Explicit closing engine connection (#7570)
    
    (cherry picked from commit e5739fbbd2eb9150a5ec889cd38f588501945a43)
---
 superset/views/core.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/superset/views/core.py b/superset/views/core.py
index 019d400..32cabad 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 # pylint: disable=C,R,W
+from contextlib import closing
 from datetime import datetime, timedelta
 import inspect
 import logging
@@ -38,7 +39,8 @@ import pandas as pd
 import simplejson as json
 import sqlalchemy as sqla
 from sqlalchemy import (
-    and_, Column, create_engine, ForeignKey, Integer, MetaData, or_, Table, update)
+    and_, Column, create_engine, ForeignKey, Integer, MetaData, or_, select, Table,
+    update)
 from sqlalchemy.engine.url import make_url
 from sqlalchemy.exc import IntegrityError
 from werkzeug.routing import BaseConverter
@@ -1806,8 +1808,9 @@ class Superset(BaseSupersetView):
                 connect_args['configuration'] = configuration
 
             engine = create_engine(uri, **engine_params)
-            engine.connect()
-            return json_success(json.dumps(engine.table_names(), indent=4))
+
+            with closing(engine.connect()) as conn:
+                return json_success(json.dumps(conn.scalar(select([1]))))
         except Exception as e:
             logging.exception(e)
             return json_error_response((