mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
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.connectors.connector_registry import ConnectorRegistry
|
||||||
from superset.views.base import (
|
from superset.views.base import (
|
||||||
BaseSupersetView, DatasourceFilter, DeleteMixin,
|
BaseSupersetView, DatasourceFilter, DeleteMixin,
|
||||||
get_datasource_exist_error_mgs, ListWidgetWithCheckboxes, SupersetModelView,
|
get_datasource_exist_error_msg, ListWidgetWithCheckboxes, SupersetModelView,
|
||||||
validate_json, YamlExportMixin,
|
validate_json, YamlExportMixin,
|
||||||
)
|
)
|
||||||
from . import models
|
from . import models
|
||||||
@ -284,7 +284,7 @@ class DruidDatasourceModelView(DatasourceModelView, DeleteMixin, YamlExportMixin
|
|||||||
datasource.cluster.id)
|
datasource.cluster.id)
|
||||||
)
|
)
|
||||||
if db.session.query(query.exists()).scalar():
|
if db.session.query(query.exists()).scalar():
|
||||||
raise Exception(get_datasource_exist_error_mgs(
|
raise Exception(get_datasource_exist_error_msg(
|
||||||
datasource.full_name))
|
datasource.full_name))
|
||||||
|
|
||||||
def post_add(self, datasource):
|
def post_add(self, datasource):
|
||||||
|
@ -18,7 +18,7 @@ from past.builtins import basestring
|
|||||||
from superset import appbuilder, db, security_manager, utils
|
from superset import appbuilder, db, security_manager, utils
|
||||||
from superset.connectors.base.views import DatasourceModelView
|
from superset.connectors.base.views import DatasourceModelView
|
||||||
from superset.views.base import (
|
from superset.views.base import (
|
||||||
DatasourceFilter, DeleteMixin, get_datasource_exist_error_mgs,
|
DatasourceFilter, DeleteMixin, get_datasource_exist_error_msg,
|
||||||
ListWidgetWithCheckboxes, SupersetModelView, YamlExportMixin,
|
ListWidgetWithCheckboxes, SupersetModelView, YamlExportMixin,
|
||||||
)
|
)
|
||||||
from . import models
|
from . import models
|
||||||
@ -252,7 +252,7 @@ class TableModelView(DatasourceModelView, DeleteMixin, YamlExportMixin): # noqa
|
|||||||
models.SqlaTable.database_id == table.database.id)
|
models.SqlaTable.database_id == table.database.id)
|
||||||
if db.session.query(table_query.exists()).scalar():
|
if db.session.query(table_query.exists()).scalar():
|
||||||
raise Exception(
|
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
|
# Fail before adding if the table can't be found
|
||||||
try:
|
try:
|
||||||
@ -300,12 +300,26 @@ class TableModelView(DatasourceModelView, DeleteMixin, YamlExportMixin): # noqa
|
|||||||
def refresh(self, tables):
|
def refresh(self, tables):
|
||||||
if not isinstance(tables, list):
|
if not isinstance(tables, list):
|
||||||
tables = [tables]
|
tables = [tables]
|
||||||
|
successes = []
|
||||||
|
failures = []
|
||||||
for t in tables:
|
for t in tables:
|
||||||
t.fetch_metadata()
|
try:
|
||||||
msg = _(
|
t.fetch_metadata()
|
||||||
'Metadata refreshed for the following table(s): %(tables)s',
|
successes.append(t)
|
||||||
tables=', '.join([t.table_name for t in tables]))
|
except Exception:
|
||||||
flash(msg, 'info')
|
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/')
|
return redirect('/tablemodelview/list/')
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ def api(f):
|
|||||||
return functools.update_wrapper(wraps, 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)
|
return __('Datasource %(name)s already exists', name=full_name)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user