Skip to content

Commit

Permalink
[testconn] Explicit closing engine connection (apache#7570)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored May 22, 2019
1 parent 6b9790c commit e5739fb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,7 +38,7 @@
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
Expand Down Expand Up @@ -1813,8 +1814,9 @@ def testconn(self):
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((
Expand Down

0 comments on commit e5739fb

Please sign in to comment.