Skip to content

Commit

Permalink
Move to db_engine_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-liu committed Feb 15, 2017
1 parent b5e330d commit e2c7363
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
20 changes: 20 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from collections import namedtuple, defaultdict
from flask_babel import lazy_gettext as _
from superset import utils

import inspect
import textwrap
import time
Expand Down Expand Up @@ -91,6 +93,11 @@ def handle_cursor(cls, cursor, query, session):
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
Expand Down Expand Up @@ -312,6 +319,19 @@ def handle_cursor(cls, cursor, query, session):
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'
Expand Down
11 changes: 1 addition & 10 deletions superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,7 @@ def handle_error(msg):
result_proxy = engine.execute(query.executed_sql, schema=query.schema)
except Exception as e:
logging.exception(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']
)
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
Expand Down

0 comments on commit e2c7363

Please sign in to comment.