mirror of
https://github.com/apache/superset.git
synced 2026-06-09 09:39:25 +00:00
[testconn] Explicit closing engine connection (#7570)
This commit is contained in:
@@ -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
|
||||
@@ -37,7 +38,7 @@ from flask_babel import lazy_gettext as _
|
||||
import pandas as pd
|
||||
import simplejson as json
|
||||
import sqlalchemy as sqla
|
||||
from sqlalchemy import and_, create_engine, MetaData, or_, update
|
||||
from sqlalchemy import and_, create_engine, MetaData, or_, select, update
|
||||
from sqlalchemy.engine.url import make_url
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from werkzeug.routing import BaseConverter
|
||||
@@ -1813,8 +1814,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((
|
||||
|
||||
Reference in New Issue
Block a user