betodealmeida commented on a change in pull request #7621: fix: Better error
message for dashboard import
URL:
https://github.com/apache/incubator-superset/pull/7621#discussion_r292995922
##########
File path: superset/connectors/sqla/models.py
##########
@@ -945,8 +946,12 @@ def lookup_sqlatable(table):
).first()
def lookup_database(table):
- return db.session.query(Database).filter_by(
- database_name=table.params_dict['database_name']).one()
+ try:
+ return db.session.query(Database).filter_by(
+ database_name=table.params_dict['database_name']).one()
+ except NoResultFound:
+ raise Exception(_("Database '{}' is not found".format(
Review comment:
I think it would be better to raise a custom exception here:
```python
raise DatabaseNotFound(...)
```
And then in `superset/views/core.py` we can be more specific:
```python
try:
dashboard_import_export.import_dashboards(db.session, f.stream)
except DatabaseNotFound as e:
flash(_(
'Cannot import dashboard: {}\n'
'Make sure to create the database before '
'importing the dashboard.'
).format(e), 'danger')
except Exception as e:
flash(_(
'An unknown error occurred. '
'Please contact your Superset administrator'
), 'danger')
```
My personal rule for error messages is that (1) they should be as specific
as possible and (2) they should have an action that the user can take (even if
it's just contacting the admin).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]