-
Notifications
You must be signed in to change notification settings - Fork 14k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(explore): allow opening charts with missing dataset #12705
Conversation
a65f780
to
2d58d3f
Compare
@@ -28,6 +28,7 @@ import { DropDownProps } from 'antd/lib/dropdown'; | |||
*/ | |||
// eslint-disable-next-line no-restricted-imports | |||
export { | |||
Alert, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanted to use Antd Alert, but it looks inconsistent with the error box in chart container.
label: string; | ||
datasource?: DatasourceControl; | ||
interface DatasourceControl extends ControlConfig { | ||
datasource?: DatasourceMeta; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bycatch: reuse typing from @superset-ui/chart-controls
.
return ( | ||
<DatasourceContainer> | ||
<Control {...datasourceControl} name="datasource" actions={actions} /> | ||
{datasource.id != null && mainBody} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Datasource ID is null
when it is unavailable.
"name": datasource_name, | ||
"columns": [], | ||
"metrics": [], | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a dummy datasource is easier than fixing countless places on the frontend where it's expected to exist.
Returns None if `datasource_type` is not registered or `datasource_id` does | ||
not exists.""" | ||
if datasource_type not in cls.sources: | ||
raise DatasetNotFoundError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle_api_exception
will be able to render the error properly.
return json_error_response( | ||
f"{DatasetForbiddenError.message}", DatasetForbiddenError.status | ||
) | ||
raise DatasetForbiddenError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle_api_exception
will be able to render the error properly.
@@ -504,6 +505,8 @@ def base_json_conv( # pylint: disable=inconsistent-return-statements,too-many-r | |||
return obj.decode("utf-8") | |||
except Exception: # pylint: disable=broad-except | |||
return "[bytes]" | |||
if isinstance(obj, LazyString): | |||
return str(obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure translations can be properly outputted in json API response.
@@ -26,7 +26,10 @@ | |||
ImportFailedError, | |||
UpdateFailedError, | |||
) | |||
from superset.views.base import get_datasource_exist_error_msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to reduce the change of circular imports.
Codecov Report
@@ Coverage Diff @@
## master #12705 +/- ##
==========================================
- Coverage 66.89% 59.17% -7.72%
==========================================
Files 1022 965 -57
Lines 49994 47218 -2776
Branches 4892 4405 -487
==========================================
- Hits 33442 27942 -5500
- Misses 16427 19276 +2849
+ Partials 125 0 -125
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
4b6409f
to
41b3192
Compare
41b3192
to
bc75a7c
Compare
5ad2399
to
d2f47a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Minor comments, thanks fixing the translations, too!
<span className="title-select">{datasource.name}</span> | ||
</Tooltip> | ||
{/* Add a tooltip only for long dataset names */} | ||
{datasource.name.length > 20 ? ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be nice to have this in a constants.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ideally should be more sophisticated where we display tooltip only when we detect text has been cutoff. This is just a heuristic number that works for the smallest panel width (300px).
It's a very local feature so I wouldn't put it into another file.
<> | ||
<p> | ||
{t( | ||
'The dataset linked to this chart may have been deleted.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we be more explicit here as in the other error - "Dataset does not exist".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking is this: the dataset does not exist for two reasons, either it never existed or has been deleted. Since the latter is the most likely case, we inform users about this possibility, but also show reservations with "may" to be more accurate.
I think a little bit more color in copy is more helpful comparing to repeating the same general message over and over.
return ( | ||
"""Safely get a datasource without raising any errors. | ||
Returns None if `datasource_type` is not registered or `datasource_id` does | ||
not exists.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
not exists.""" | |
not exist.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is inaccurate. I decided to still raise an error to avoid making too many changes.
Will delete.
@@ -54,7 +57,7 @@ class DatasetExistsValidationError(ValidationError): | |||
|
|||
def __init__(self, table_name: str) -> None: | |||
super().__init__( | |||
get_datasource_exist_error_msg(table_name), field_name="table_name" | |||
[get_dataset_exist_error_msg(table_name)], field_name="table_name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch 👍
@@ -206,7 +206,7 @@ def digest(self) -> str: | |||
""" | |||
Returns a MD5 HEX digest that makes this dashboard unique | |||
""" | |||
return utils.md5_hex(self.params) | |||
return utils.md5_hex(self.params or "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that it matters, but I've always been allergic to md5 on empty string:
>>> import hashlib
>>> hashlib.md5(''.encode()).hexdigest()
'd41d8cd98f00b204e9800998ecf8427e'
return utils.md5_hex(self.params or "") | |
return utils.md5_hex(self.params) if self.params else '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll return None
here just to be more explicit. The original change is for avoiding an uncaught exception, explicitly returning None forces the downstream handle the case of missing params
more properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm. I'll keep utils.md5_hex(self.params or "")
since this key is also used in thumbnail URLs:
return f"/api/v1/chart/{self.id}/thumbnail/{self.digest}/"
We can make a follow up PR to rename digest
to thumbnail_key
(for both chart and dashboard) if we think it's necessary.
d2f47a4
to
04fab5e
Compare
04fab5e
to
aa350ef
Compare
A possible followup would be to add "Delete chart" shortcut CTA to make it easier for chart owners to delete outdated charts. |
* master: (52 commits) docs: Updates to Superset Site for 1.0 (apache#12626) test(native-filters): scoping tree in native filters modal (apache#12655) Fix tests errors and warnings - iteration 3 (apache#12212) (apache#12219) Fix tests errors and warnings - iteration 5 (apache#12212) (apache#12224) Fix tests errors and warnings - iteration 6 (apache#12212) (apache#12227) feat(native-filters): apply scoping of native filters to dashboard (apache#12716) Fix tests errors and warnings - iteration 4 (apache#12212) (apache#12223) Fix tests errors and warnings - iteration 7 (apache#12212) (apache#12245) fix: missing select menu background (apache#12759) fix(explore): incorrect missing datasource condition (apache#12758) feat: default timepicker to last week when dataset is changed (apache#12609) feat(explore): allow opening charts with missing dataset (apache#12705) chore: upgrade Cypress to 6.2.1 (apache#12605) refactor(explore): Enhance Dataset and Control panel Collapse components (apache#12218) feat: Adding option to set_database_uri CLI command (apache#12740) docs: Fixed typo on line 348 (apache#12739) Fix tests errors and warnings - iteration 2 (apache#12212) (apache#12214) docs: Remove gatsby-plugin-offline (apache#12693) test: oracle engine spec (apache#12615) test: hive db engine spec (apache#12520) ...
SUMMARY
Allow opening charts with missing dataset as proposed in #12464 (comment). Alternative solution for #12468 .
Also did some refactoring on
get_datasource
error handling.Closes #12464
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before
Opening a chart with missing dataset redirects to chart list with a flash message.
After
Chart can open, all control params retained; users are offered a way to quickly switch to a valid dataset.
TEST PLAN
Manual
ADDITIONAL INFORMATION