mirror of
https://github.com/apache/superset.git
synced 2026-04-17 15:15:20 +00:00
Better error handling for presto (#2161)
* Better error handling for presto * Move to db_engine_spec
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user