diff --git a/superset/assets/javascripts/explorev2/components/DisplayQueryButton.jsx b/superset/assets/javascripts/explorev2/components/DisplayQueryButton.jsx
index a8aea850f7..1912016b4a 100644
--- a/superset/assets/javascripts/explorev2/components/DisplayQueryButton.jsx
+++ b/superset/assets/javascripts/explorev2/components/DisplayQueryButton.jsx
@@ -57,7 +57,7 @@ export default class DisplayQueryButton extends React.PureComponent {
});
}
beforeOpen() {
- if (this.props.chartStatus === 'loading' || this.props.chartStatus === null) {
+ if (['loading', null].indexOf(this.props.chartStatus) >= 0 || !this.props.queryResponse) {
this.fetchQuery();
} else {
this.setStateFromQueryResponse();
@@ -72,11 +72,13 @@ export default class DisplayQueryButton extends React.PureComponent {
/>);
} else if (this.state.error) {
return
{this.state.error}
;
+ } else if (this.state.query) {
+ return (
+
+ {this.state.query}
+ );
}
- return (
-
- {this.state.query}
- );
+ return null;
}
render() {
return (
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index d1dc7a6bd1..1ed45023fb 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -547,7 +547,8 @@ class SqlaTable(Model, BaseDatasource):
except Exception as e:
status = QueryStatus.FAILED
logging.exception(e)
- error_message = str(e)
+ error_message = (
+ self.database.db_engine_spec.extract_error_message(e))
return QueryResult(
status=status,
diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index 99d182eb73..fae9c58b56 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -484,11 +484,12 @@ class PrestoEngineSpec(BaseEngineSpec):
@classmethod
def extract_error_message(cls, e):
- if hasattr(e, 'orig') \
- and type(e.orig).__name__ == 'DatabaseError' \
- and isinstance(e.orig[0], dict):
+ if (
+ hasattr(e, 'orig') and
+ type(e.orig).__name__ == 'DatabaseError' and
+ isinstance(e.orig[0], dict)):
error_dict = e.orig[0]
- e = '{} at {}: {}'.format(
+ return '{} at {}: {}'.format(
error_dict['errorName'],
error_dict['errorLocation'],
error_dict['message']