You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2018/08/02 06:10:50 UTC
[incubator-superset] branch master updated: Replace metadata
refresh stacktrace with danger flash (#5536)
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 906dcd8 Replace metadata refresh stacktrace with danger flash (#5536)
906dcd8 is described below
commit 906dcd84a921a7111332a3c9d7b4649f9a3f9643
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Thu Aug 2 09:10:47 2018 +0300
Replace metadata refresh stacktrace with danger flash (#5536)
* Replace stacktrace with danger flash
* Group successful and failed refreshes and fix typos
* Fix linting
---
superset/connectors/druid/views.py | 4 ++--
superset/connectors/sqla/views.py | 28 +++++++++++++++++++++-------
superset/views/base.py | 2 +-
3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/superset/connectors/druid/views.py b/superset/connectors/druid/views.py
index 7e50536..5e5ba0d 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 cceee9a..01c68c7 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 25de44d..5d90284 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)