Apply appropriate type conversion for viz form_data #1334
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
On the Dashboard view, the
form_data
is passed in as a regular dict. This is then passed as**kwargs
to WTForms which as the note below describes doesn't do proper type conversion.u'false'
becomesTrue
which is not what we want. This is not currently impacting users because slices always pull data from thejson_endpoint
but should still be fixed because the data inside the rendered html is inconsistent.Solution
If passing just one parameter as
form_data
, the WTForms constructor will do proper type conversion as if theform_data
came from a POST. This is why this bug doesn't surface when using thejson_endpoint
to get slice data, but it does on the dashboard page. The fix is to pass theform_data
parameter rather than as**kwargs
.Example reproduction steps:
data-dashboard
in the markup. Note thatform_data.donut
istrue
when it should befalse
.You have to save as donut and then back to pie to reproduce because initially donut isn't in the params object. You'll note that the Genders slice still renders as a pie correctly without this fix, but only because internally slices render using data from
json_endpoint
in whichform_data
always follows theform = form_class(form_data)
code path instead of being used as a**kwargs
. This fix is still important because theform_data
is out of sync with the real values and could be problematic in the future or in the present to people who are extending Caravel to useform_data
now (which is how I discovered it).WTForms docs
@mistercrunch