From 05fc099de31e594b5df30dfb6013a59fd35962dc Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Wed, 6 Apr 2022 11:07:13 +0300 Subject: [PATCH] fix(sqllab): null database with backend persistence --- .../src/SqlLab/actions/sqlLab.js | 21 ++++++++++++++----- superset/models/sql_lab.py | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index 02e07d5831e9b..e602b796bd368 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -1393,10 +1393,21 @@ export function queryEditorSetFunctionNames(queryEditor, dbId) { functionNames: json.function_names, }), ) - .catch(() => - dispatch( - addDangerToast(t('An error occurred while fetching function names.')), - ), - ); + .catch(err => { + if (err.status === 404) { + // for databases that have been deleted, just reset the function names + dispatch({ + type: QUERY_EDITOR_SET_FUNCTION_NAMES, + queryEditor, + functionNames: [], + }); + } else { + dispatch( + addDangerToast( + t('An error occurred while fetching function names.'), + ), + ); + } + }); }; } diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py index 6a3b4ad8bfd7c..57d722070523c 100644 --- a/superset/models/sql_lab.py +++ b/superset/models/sql_lab.py @@ -118,7 +118,7 @@ def to_dict(self) -> Dict[str, Any]: "changedOn": self.changed_on, "changed_on": self.changed_on.isoformat(), "dbId": self.database_id, - "db": self.database.database_name, + "db": self.database.database_name if self.database else None, "endDttm": self.end_time, "errorMessage": self.error_message, "executedSql": self.executed_sql,