diff --git a/superset-frontend/src/SqlLab/App.jsx b/superset-frontend/src/SqlLab/App.jsx
index 9707b8547b211..0b3cbbbd58f99 100644
--- a/superset-frontend/src/SqlLab/App.jsx
+++ b/superset-frontend/src/SqlLab/App.jsx
@@ -109,7 +109,7 @@ if (sqlLabMenu) {
const Application = () => (
-
+
);
diff --git a/superset-frontend/src/SqlLab/components/App.jsx b/superset-frontend/src/SqlLab/components/App.jsx
index 01d6ca3e99ffb..f1c21be33615c 100644
--- a/superset-frontend/src/SqlLab/components/App.jsx
+++ b/superset-frontend/src/SqlLab/components/App.jsx
@@ -125,7 +125,7 @@ class App extends React.PureComponent {
content = (
<>
-
+
>
);
}
diff --git a/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx b/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx
index d996417e777e2..b4170b28b1d32 100644
--- a/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx
+++ b/superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx
@@ -39,6 +39,7 @@ const propTypes = {
databases: PropTypes.object.isRequired,
queries: PropTypes.object.isRequired,
queryEditors: PropTypes.array,
+ requestedQuery: PropTypes.object,
tabHistory: PropTypes.array.isRequired,
tables: PropTypes.array.isRequired,
offline: PropTypes.bool,
@@ -48,6 +49,7 @@ const propTypes = {
const defaultProps = {
queryEditors: [],
offline: false,
+ requestedQuery: null,
saveQueryWarning: null,
scheduleQueryWarning: null,
};
@@ -101,7 +103,7 @@ class TabbedSqlEditors extends React.PureComponent {
// merge post form data with GET search params
const query = {
- ...this.props.formData,
+ ...this.props.requestedQuery,
...URI(window.location).search(true),
};
@@ -379,7 +381,7 @@ class TabbedSqlEditors extends React.PureComponent {
TabbedSqlEditors.propTypes = propTypes;
TabbedSqlEditors.defaultProps = defaultProps;
-function mapStateToProps({ sqlLab, common }) {
+function mapStateToProps({ sqlLab, common, requestedQuery }) {
return {
databases: sqlLab.databases,
queryEditors: sqlLab.queryEditors,
@@ -393,6 +395,7 @@ function mapStateToProps({ sqlLab, common }) {
maxRow: common.conf.SQL_MAX_ROW,
saveQueryWarning: common.conf.SQLLAB_SAVE_WARNING_MESSAGE,
scheduleQueryWarning: common.conf.SQLLAB_SCHEDULE_WARNING_MESSAGE,
+ requestedQuery,
};
}
function mapDispatchToProps(dispatch) {
diff --git a/superset-frontend/src/SqlLab/reducers/getInitialState.js b/superset-frontend/src/SqlLab/reducers/getInitialState.js
index 470816b839338..fd3c8ae747d0d 100644
--- a/superset-frontend/src/SqlLab/reducers/getInitialState.js
+++ b/superset-frontend/src/SqlLab/reducers/getInitialState.js
@@ -26,6 +26,7 @@ export default function getInitialState({
tab_state_ids: tabStateIds = [],
databases,
queries: queries_,
+ requested_query: requestedQuery,
}) {
/**
* Before YYYY-MM-DD, the state for SQL Lab was stored exclusively in the
@@ -180,6 +181,7 @@ export default function getInitialState({
tables,
queriesLastUpdate: Date.now(),
},
+ requestedQuery,
messageToasts: getToastsFromPyFlashMessages(
(common || {}).flash_messages || [],
),
diff --git a/superset/views/core.py b/superset/views/core.py
index 13cc80e5ccdc8..b38a5585d09e5 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -2703,7 +2703,7 @@ def profile(self, username):
)
@staticmethod
- def _get_sqllab_payload(user_id: int) -> Dict[str, Any]:
+ def _get_sqllab_tabs(user_id: int) -> Dict[str, Any]:
# send list of tab state ids
tabs_state = (
db.session.query(TabState.id, TabState.label)
@@ -2743,8 +2743,6 @@ def _get_sqllab_payload(user_id: int) -> Dict[str, Any]:
}
return {
- "defaultDbId": config["SQLLAB_DEFAULT_DBID"],
- "common": common_bootstrap_payload(),
"tab_state_ids": tabs_state,
"active_tab": active_tab.to_dict() if active_tab else None,
"databases": databases,
@@ -2755,14 +2753,22 @@ def _get_sqllab_payload(user_id: int) -> Dict[str, Any]:
@expose("/sqllab", methods=["GET", "POST"])
def sqllab(self):
"""SQL Editor"""
- payload = self._get_sqllab_payload(g.user.get_id())
- form_data = request.form.get('form_data')
- try:
- payload['form_data'] = json.loads(form_data)
- except:
- pass
+ payload = {
+ "defaultDbId": config["SQLLAB_DEFAULT_DBID"],
+ "common": common_bootstrap_payload(),
+ }
+
+ tabs_data = self._get_sqllab_tabs(g.user.get_id())
+ payload.update(tabs_data)
+
+ form_data = request.form.get("form_data")
+ if form_data:
+ try:
+ payload["requested_query"] = json.loads(form_data)
+ except json.JSONDecodeError:
+ pass
bootstrap_data = json.dumps(
- payload, default=utils.pessimistic_json_iso_dttm_ser,
+ payload, default=utils.pessimistic_json_iso_dttm_ser
)
return self.render_template(
diff --git a/tests/core_tests.py b/tests/core_tests.py
index 8b4ce6978edab..19d1b662a2bd6 100644
--- a/tests/core_tests.py
+++ b/tests/core_tests.py
@@ -1168,7 +1168,7 @@ def test_sqllab_backend_persistence_payload(self):
# we should have only 1 query returned, since the second one is not
# associated with any tabs
- payload = views.Superset._get_sqllab_payload(user_id=user_id)
+ payload = views.Superset._get_sqllab_tabs(user_id=user_id)
self.assertEqual(len(payload["queries"]), 1)