Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sql lab] improve error messages #3308

Merged
merged 2 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions superset/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,17 @@ def adjust_database_uri(cls, uri, selected_schema=None):
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'
Expand Down
2 changes: 1 addition & 1 deletion superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def handle_error(msg):
session.commit()
payload.update({
'status': query.status,
'error_essage': msg,
'error': msg,
})
return payload

Expand Down
12 changes: 6 additions & 6 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def get_error_msg():
return error_msg


def json_error_response(msg, status=None, stacktrace=None):
data = {'error': str(msg)}
if stacktrace:
data['stacktrace'] = stacktrace
status = status if status else 500
def json_error_response(msg=None, status=500, stacktrace=None, payload=None):
if not payload:
payload = {'error': str(msg)}
if stacktrace:
payload['stacktrace'] = stacktrace
return Response(
json.dumps(data),
json.dumps(payload, default=utils.json_iso_dttm_ser),
status=status, mimetype="application/json")


Expand Down
5 changes: 2 additions & 3 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,13 +2072,12 @@ def sql_json(self):
# 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>")
Expand Down