Skip to content

Commit

Permalink
add try catch and type checking for parsed dash metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace committed Mar 18, 2020
1 parent 9752ff4 commit 2c2b020
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions superset/views/utils.py
Expand Up @@ -285,17 +285,27 @@ def get_dashboard_extra_filters(
):
return []

# does this dashboard have default filters?
json_metadata = json.loads(dashboard.json_metadata)
default_filters = json.loads(json_metadata.get("default_filters", "null"))
if not default_filters:
return []

# are default filters applicable to the given slice?
filter_scopes = json_metadata.get("filter_scopes", {})
layout = json.loads(dashboard.position_json or "{}")

return build_extra_filters(layout, filter_scopes, default_filters, slice_id)
try:
# does this dashboard have default filters?
json_metadata = json.loads(dashboard.json_metadata)
default_filters = json.loads(json_metadata.get("default_filters", "null"))
if not default_filters:
return []

# are default filters applicable to the given slice?
filter_scopes = json_metadata.get("filter_scopes", {})
layout = json.loads(dashboard.position_json or "{}")

if (
isinstance(layout, dict)
and isinstance(filter_scopes, dict)
and isinstance(default_filters, dict)
):
return build_extra_filters(layout, filter_scopes, default_filters, slice_id)
except json.JSONDecodeError:
pass

return []


def build_extra_filters(
Expand Down

0 comments on commit 2c2b020

Please sign in to comment.