diff --git a/superset/connectors/druid/views.py b/superset/connectors/druid/views.py index 7e50536195..5e5ba0da93 100644 --- a/superset/connectors/druid/views.py +++ b/superset/connectors/druid/views.py @@ -21,7 +21,7 @@ from superset.connectors.base.views import DatasourceModelView from superset.connectors.connector_registry import ConnectorRegistry from superset.views.base import ( BaseSupersetView, DatasourceFilter, DeleteMixin, - get_datasource_exist_error_mgs, ListWidgetWithCheckboxes, SupersetModelView, + get_datasource_exist_error_msg, ListWidgetWithCheckboxes, SupersetModelView, validate_json, YamlExportMixin, ) from . import models @@ -284,7 +284,7 @@ class DruidDatasourceModelView(DatasourceModelView, DeleteMixin, YamlExportMixin datasource.cluster.id) ) if db.session.query(query.exists()).scalar(): - raise Exception(get_datasource_exist_error_mgs( + raise Exception(get_datasource_exist_error_msg( datasource.full_name)) def post_add(self, datasource): diff --git a/superset/connectors/sqla/views.py b/superset/connectors/sqla/views.py index cceee9a8c0..01c68c7ea3 100644 --- a/superset/connectors/sqla/views.py +++ b/superset/connectors/sqla/views.py @@ -18,7 +18,7 @@ from past.builtins import basestring from superset import appbuilder, db, security_manager, utils from superset.connectors.base.views import DatasourceModelView from superset.views.base import ( - DatasourceFilter, DeleteMixin, get_datasource_exist_error_mgs, + DatasourceFilter, DeleteMixin, get_datasource_exist_error_msg, ListWidgetWithCheckboxes, SupersetModelView, YamlExportMixin, ) from . import models @@ -252,7 +252,7 @@ class TableModelView(DatasourceModelView, DeleteMixin, YamlExportMixin): # noqa models.SqlaTable.database_id == table.database.id) if db.session.query(table_query.exists()).scalar(): raise Exception( - get_datasource_exist_error_mgs(table.full_name)) + get_datasource_exist_error_msg(table.full_name)) # Fail before adding if the table can't be found try: @@ -300,12 +300,26 @@ class TableModelView(DatasourceModelView, DeleteMixin, YamlExportMixin): # noqa def refresh(self, tables): if not isinstance(tables, list): tables = [tables] + successes = [] + failures = [] for t in tables: - t.fetch_metadata() - msg = _( - 'Metadata refreshed for the following table(s): %(tables)s', - tables=', '.join([t.table_name for t in tables])) - flash(msg, 'info') + try: + t.fetch_metadata() + successes.append(t) + except Exception: + failures.append(t) + + if len(successes) > 0: + success_msg = _( + 'Metadata refreshed for the following table(s): %(tables)s', + tables=', '.join([t.table_name for t in successes])) + flash(success_msg, 'info') + if len(failures) > 0: + failure_msg = _( + 'Unable to retrieve metadata for the following table(s): %(tables)s', + tables=', '.join([t.table_name for t in failures])) + flash(failure_msg, 'danger') + return redirect('/tablemodelview/list/') diff --git a/superset/views/base.py b/superset/views/base.py index 25de44d26a..5d90284de3 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -78,7 +78,7 @@ def api(f): return functools.update_wrapper(wraps, f) -def get_datasource_exist_error_mgs(full_name): +def get_datasource_exist_error_msg(full_name): return __('Datasource %(name)s already exists', name=full_name)