mirror of https://github.com/apache/superset.git
[sql lab] improve error messages (#3308)
* [sql lab] improve error messages Some error messages in non-async mode were showing as JSON or sometimes as tuples. This fixes that. * linting
This commit is contained in:
parent
2923a125db
commit
6fc837db51
|
@ -950,10 +950,10 @@ def load_random_time_series_data():
|
|||
|
||||
def load_country_map_data():
|
||||
"""Loading data for map with country map"""
|
||||
csvPath = os.path.join(DATA_FOLDER, 'birth_france_data_for_country_map.csv')
|
||||
data = pd.read_csv(csvPath, encoding="utf-8")
|
||||
csv_path = os.path.join(DATA_FOLDER, 'birth_france_data_for_country_map.csv')
|
||||
data = pd.read_csv(csv_path, encoding="utf-8")
|
||||
data['date'] = datetime.datetime.now().date()
|
||||
data.to_sql(
|
||||
data.to_sql( # pylint: disable=no-member
|
||||
'birth_france_by_region',
|
||||
db.engine,
|
||||
if_exists='replace',
|
||||
|
|
|
@ -351,6 +351,17 @@ class MySQLEngineSpec(BaseEngineSpec):
|
|||
def epoch_to_dttm(cls):
|
||||
return "from_unixtime({col})"
|
||||
|
||||
@classmethod
|
||||
def extract_error_message(cls, e):
|
||||
"""Extract error message for queries"""
|
||||
message = str(e)
|
||||
try:
|
||||
if isinstance(e.args, tuple) and len(e.args) > 1:
|
||||
message = e.args[1]
|
||||
except:
|
||||
pass
|
||||
return message
|
||||
|
||||
|
||||
class PrestoEngineSpec(BaseEngineSpec):
|
||||
engine = 'presto'
|
||||
|
|
|
@ -120,7 +120,7 @@ def execute_sql(ctask, query_id, return_results=True, store_results=False):
|
|||
session.commit()
|
||||
payload.update({
|
||||
'status': query.status,
|
||||
'error_essage': msg,
|
||||
'error': msg,
|
||||
})
|
||||
return payload
|
||||
|
||||
|
|
|
@ -31,13 +31,13 @@ def get_error_msg():
|
|||
return error_msg
|
||||
|
||||
|
||||
def json_error_response(msg, status=None, stacktrace=None):
|
||||
data = {'error': str(msg)}
|
||||
def json_error_response(msg=None, status=500, stacktrace=None, payload=None):
|
||||
if not payload:
|
||||
payload = {'error': str(msg)}
|
||||
if stacktrace:
|
||||
data['stacktrace'] = stacktrace
|
||||
status = status if status else 500
|
||||
payload['stacktrace'] = stacktrace
|
||||
return Response(
|
||||
json.dumps(data),
|
||||
json.dumps(payload, default=utils.json_iso_dttm_ser),
|
||||
status=status, mimetype="application/json")
|
||||
|
||||
|
||||
|
|
|
@ -2074,13 +2074,12 @@ class Superset(BaseSupersetView):
|
|||
# pylint: disable=no-value-for-parameter
|
||||
data = sql_lab.get_sql_results(
|
||||
query_id=query_id, return_results=True)
|
||||
payload = json.dumps(data, default=utils.json_iso_dttm_ser)
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
return json_error_response("{}".format(e))
|
||||
if data.get('status') == QueryStatus.FAILED:
|
||||
return json_error_response(payload)
|
||||
return json_success(payload)
|
||||
return json_error_response(payload=data)
|
||||
return json_success(json.dumps(data, default=utils.json_iso_dttm_ser))
|
||||
|
||||
@has_access
|
||||
@expose("/csv/<client_id>")
|
||||
|
|
Loading…
Reference in New Issue