Skip to content

Commit

Permalink
fix(viz): downgrade exception for missing viz/datasource (apache#11173)
Browse files Browse the repository at this point in the history
* fix(viz): downgrade exception for missing datasource

* add translations
  • Loading branch information
villebro authored and auxten committed Nov 20, 2020
1 parent d6887a4 commit 3e8830a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
45 changes: 32 additions & 13 deletions superset/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from flask_appbuilder.security.sqla import models as ab_models
from flask_appbuilder.security.sqla.models import User
from flask_babel import gettext as __
from sqlalchemy.orm.exc import NoResultFound

import superset.models.core as models
from superset import (
Expand Down Expand Up @@ -490,16 +491,25 @@ def check_datasource_perms(
SupersetError(
error_type=SupersetErrorType.UNKNOWN_DATASOURCE_TYPE_ERROR,
level=ErrorLevel.ERROR,
message="Could not determine datasource type",
message=__("Could not determine datasource type"),
)
)

viz_obj = get_viz(
datasource_type=datasource_type,
datasource_id=datasource_id,
form_data=form_data,
force=False,
)
try:
viz_obj = get_viz(
datasource_type=datasource_type,
datasource_id=datasource_id,
form_data=form_data,
force=False,
)
except NoResultFound:
raise SupersetSecurityException(
SupersetError(
error_type=SupersetErrorType.UNKNOWN_DATASOURCE_TYPE_ERROR,
level=ErrorLevel.ERROR,
message=__("Could not find viz object"),
)
)

viz_obj.raise_for_access()

Expand All @@ -518,12 +528,21 @@ def check_slice_perms(_self: Any, slice_id: int) -> None:
form_data, slc = get_form_data(slice_id, use_slice_data=True)

if slc:
viz_obj = get_viz(
datasource_type=slc.datasource.type,
datasource_id=slc.datasource.id,
form_data=form_data,
force=False,
)
try:
viz_obj = get_viz(
datasource_type=slc.datasource.type,
datasource_id=slc.datasource.id,
form_data=form_data,
force=False,
)
except NoResultFound:
raise SupersetSecurityException(
SupersetError(
error_type=SupersetErrorType.UNKNOWN_DATASOURCE_TYPE_ERROR,
level=ErrorLevel.ERROR,
message="Could not find viz object",
)
)

viz_obj.raise_for_access()

Expand Down
2 changes: 1 addition & 1 deletion superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __init__(
force: bool = False,
) -> None:
if not datasource:
raise Exception(_("Viz is missing a datasource"))
raise QueryObjectValidationError(_("Viz is missing a datasource"))

self.datasource = datasource
self.request = request
Expand Down

0 comments on commit 3e8830a

Please sign in to comment.