mirror of https://github.com/apache/superset.git
Replace metadata refresh stacktrace with danger flash (#5536)
* Replace stacktrace with danger flash * Group successful and failed refreshes and fix typos * Fix linting
This commit is contained in:
parent
4bf69a7260
commit
906dcd84a9
|
@ -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):
|
||||
|
|
|
@ -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/')
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue