This is an automated email from the ASF dual-hosted git repository.
christine pushed a commit to branch release--0.31
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/release--0.31 by this push:
new db0235f Fix database typeahead in SQL Lab (#6917)
db0235f is described below
commit db0235fbdbd6437315bdb6dd2ba1259c6b27b2cc
Author: Beto Dealmeida <roberto@dealmeida.net>
AuthorDate: Tue Feb 19 16:10:17 2019 -0800
Fix database typeahead in SQL Lab (#6917)
* Fix database typeahead in SQL Lab
* Fix lint
* Use string interpolation
(cherry picked from commit 25ec00b3c6717a1800199b685ed160b38bc0ee17)
---
superset/assets/src/components/TableSelector.jsx | 6 +++++-
superset/views/core.py | 15 ++++++++++-----
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/superset/assets/src/components/TableSelector.jsx b/superset/assets/src/components/TableSelector.jsx
index 6130fc6..0452854 100644
--- a/superset/assets/src/components/TableSelector.jsx
+++ b/superset/assets/src/components/TableSelector.jsx
@@ -111,7 +111,11 @@ export default class TableSelector extends React.PureComponent {
if (data.result.length === 0) {
this.props.handleError(t("It seems you don't have access to any database"));
}
- return data.result;
+ return data.result.map(row => ({
+ ...row,
+ // label is used for the typeahead
+ label: `${row.backend} ${row.database_name}`,
+ }));
}
fetchTables(force, substr) {
// This can be large so it shouldn't be put in the Redux store
diff --git a/superset/views/core.py b/superset/views/core.py
index f7672f6..84ffe26 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1524,12 +1524,17 @@ class Superset(BaseSupersetView):
db.session
.query(models.Database)
.filter_by(id=db_id)
- .one()
+ .first()
)
- schemas = database.all_schema_names(cache=database.schema_cache_enabled,
- cache_timeout=database.schema_cache_timeout,
- force=force_refresh)
- schemas = security_manager.schemas_accessible_by_user(database, schemas)
+ if database:
+ schemas = database.all_schema_names(
+ cache=database.schema_cache_enabled,
+ cache_timeout=database.schema_cache_timeout,
+ force=force_refresh)
+ schemas = security_manager.schemas_accessible_by_user(database, schemas)
+ else:
+ schemas = []
+
return Response(
json.dumps({'schemas': schemas}),
mimetype='application/json')
|