[testconn] Explicit closing engine connection (#7570)

This commit is contained in:
John Bodley 2019-05-22 09:42:03 -07:00 committed by GitHub
parent 6b9790c8b1
commit e5739fbbd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -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((