Skip to content

Commit

Permalink
Validate JSON in slice's params on save (#3720)
Browse files Browse the repository at this point in the history
fixes #3507

This prevents malformed JSON from getting saved in a slice's params. It
also prevents the issue described in #3507 from happening though as a
result malformed slices will render using default control values.
  • Loading branch information
mistercrunch authored Oct 26, 2017
1 parent c4b6324 commit a9b6d11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ def json_data(self):

@property
def form_data(self):
form_data = json.loads(self.params)
form_data = {}
try:
form_data = json.loads(self.params)
except Exception as e:
logging.error("Malformed json in slice's params")
logging.exception(e)
form_data.update({
'slice_id': self.id,
'viz_type': self.viz_type,
Expand Down
4 changes: 4 additions & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@ class SliceModelView(SupersetModelView, DeleteMixin): # noqa
'viz_type': _("Visualization Type"),
}

def pre_add(self, obj):
utils.validate_json(obj.params)

def pre_update(self, obj):
utils.validate_json(obj.params)
check_ownership(obj)

def pre_delete(self, obj):
Expand Down

0 comments on commit a9b6d11

Please sign in to comment.