Skip to content

Commit

Permalink
[sqllab] Fix sql lab resolution link (apache#5216)
Browse files Browse the repository at this point in the history
* pass link

* update frontend to show link differently

* nits
  • Loading branch information
timifasubaa authored Jun 20, 2018
1 parent 70679d4 commit 93cdf60
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
16 changes: 12 additions & 4 deletions superset/assets/src/SqlLab/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export function querySuccess(query, results) {
return { type: QUERY_SUCCESS, query, results };
}

export function queryFailed(query, msg) {
return { type: QUERY_FAILED, query, msg };
export function queryFailed(query, msg, link) {
return { type: QUERY_FAILED, query, msg, link };
}

export function stopQuery(query) {
Expand All @@ -98,6 +98,14 @@ export function requestQueryResults(query) {
return { type: REQUEST_QUERY_RESULTS, query };
}

function getErrorLink(err) {
let link = '';
if (err.responseJSON && err.responseJSON.link) {
link = err.responseJSON.link;
}
return link;
}

export function fetchQueryResults(query) {
return function (dispatch) {
dispatch(requestQueryResults(query));
Expand All @@ -114,7 +122,7 @@ export function fetchQueryResults(query) {
if (err.responseJSON && err.responseJSON.error) {
msg = err.responseJSON.error;
}
dispatch(queryFailed(query, msg));
dispatch(queryFailed(query, msg, getErrorLink(err)));
},
});
};
Expand Down Expand Up @@ -166,7 +174,7 @@ export function runQuery(query) {
if (msg.indexOf('CSRF token') > 0) {
msg = COMMON_ERR_MESSAGES.SESSION_TIMED_OUT;
}
dispatch(queryFailed(query, msg));
dispatch(queryFailed(query, msg, getErrorLink(msg)));
},
});
};
Expand Down
6 changes: 5 additions & 1 deletion superset/assets/src/SqlLab/components/ResultSet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ export default class ResultSet extends React.PureComponent {
if (query.state === 'stopped') {
return <Alert bsStyle="warning">Query was stopped</Alert>;
} else if (query.state === 'failed') {
return <Alert bsStyle="danger">{query.errorMessage}</Alert>;
return (
<Alert bsStyle="danger">
{query.errorMessage}
{query.link && <a href={query.link}> {t('(Common errors and their resolutions)')} </a>}
</Alert>);
} else if (query.state === 'success' && query.ctas) {
return (
<div>
Expand Down
1 change: 0 additions & 1 deletion superset/assets/src/SqlLab/components/SouthPane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class SouthPane extends React.PureComponent {
} else {
results = <Alert bsStyle="info">{t('Run a query to display results here')}</Alert>;
}

const dataPreviewTabs = props.dataPreviewQueries.map(query => (
<Tab
title={t('Preview for %s', query.tableName)}
Expand Down
7 changes: 6 additions & 1 deletion superset/assets/src/SqlLab/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ export const sqlLabReducer = function (state, action) {
if (action.query.state === 'stopped') {
return state;
}
const alts = { state: 'failed', errorMessage: action.msg, endDttm: now() };
const alts = {
state: 'failed',
errorMessage: action.msg,
endDttm: now(),
link: action.link,
};
return alterInObject(state, 'queries', action.query, alts);
},
[actions.SET_ACTIVE_QUERY_EDITOR]() {
Expand Down
5 changes: 2 additions & 3 deletions superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ def execute_sql(
def handle_error(msg):
"""Local method handling error while processing the SQL"""
troubleshooting_link = config['TROUBLESHOOTING_LINK']
msg = 'Error: {}. You can find common superset errors and their \
resolutions at: {}'.format(msg, troubleshooting_link) \
if troubleshooting_link else msg
query.error_message = msg
query.status = QueryStatus.FAILED
query.tmp_table_name = None
Expand All @@ -163,6 +160,8 @@ def handle_error(msg):
'status': query.status,
'error': msg,
})
if troubleshooting_link:
payload['link'] = troubleshooting_link
return payload

if store_results and not results_backend:
Expand Down

0 comments on commit 93cdf60

Please sign in to comment.