Better error handling for presto (#2161)

* Better error handling for presto

* Move to db_engine_spec
This commit is contained in:
vera-liu
2017-02-17 10:29:35 -08:00
committed by GitHub
parent f5e3d0cc02
commit fc85034c60
2 changed files with 21 additions and 1 deletions

View File

@@ -18,6 +18,8 @@ from __future__ import unicode_literals
from collections import namedtuple, defaultdict
from flask_babel import lazy_gettext as _
from superset import utils
import inspect
import textwrap
import time
@@ -91,6 +93,11 @@ class BaseEngineSpec(object):
query object"""
pass
@classmethod
def extract_error_message(cls, e):
"""Extract error message for queries"""
return utils.error_msg_from_exception(e)
@classmethod
def sql_preprocessor(cls, sql):
"""If the SQL needs to be altered prior to running it
@@ -312,6 +319,19 @@ class PrestoEngineSpec(BaseEngineSpec):
time.sleep(1)
polled = cursor.poll()
@classmethod
def extract_error_message(cls, e):
if hasattr(e, 'orig') \
and type(e.orig).__name__ == 'DatabaseError' \
and isinstance(e.orig[0], dict):
error_dict = e.orig[0]
e = '{} at {}: {}'.format(
error_dict['errorName'],
error_dict['errorLocation'],
error_dict['message']
)
return utils.error_msg_from_exception(e)
class MssqlEngineSpec(BaseEngineSpec):
engine = 'mssql'

View File

@@ -108,7 +108,7 @@ def get_sql_results(self, query_id, return_results=True, store_results=False):
result_proxy = engine.execute(query.executed_sql, schema=query.schema)
except Exception as e:
logging.exception(e)
handle_error(utils.error_msg_from_exception(e))
handle_error(db_engine_spec.extract_error_message(e))
cursor = result_proxy.cursor
query.status = QueryStatus.RUNNING