Uh oh!
There was an error while loading. Please reload this page.
Validate component properties #264 - #340
Conversation
Uh oh!
There was an error while loading. Please reload this page.
| def add_context(*args, **kwargs): | ||
| output_value = func(*args, **kwargs) | ||
| setattr( |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| self._components[output.component_id]._validator.validate({ | ||
| output.component_property: output_value | ||
| }) | ||
| if output.component_property == 'children': |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| break | ||
| matched_state_value = matched_state.get('value', None) | ||
| args.append(matched_state_value) | ||
| setattr( |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| pass | ||
| cerberus.Validator.types_mapping['component'] =\ |
There was a problem hiding this comment.
Let us validate Component objects with cerberus (useful for children prop)
Uh oh!
There was an error while loading. Please reload this page.
| p not in ['dashEvents', 'fireEvent', 'setProps']] + ['**kwargs'] | ||
| ) | ||
| schema = {str(k): generate_property_schema(v) |
There was a problem hiding this comment.
Make cerberus schema for this dash component type.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Bachibouzouk
commented
Aug 19, 2018
Hi, I tried to I typed the command |
| # Forward declated Component class, see below. |
There was a problem hiding this comment.
did you mean 'declared'? PEP8 requires one space less :)
PS : this is my first review on dash code and I am mainly reading the code you wrote to learn more, my suggestion will mostly be about styling and spelling, I apologize in advance for that!
There was a problem hiding this comment.
my suggestion will mostly be about styling and spelling, I apologize in advance for that!
Note that we enforce PEP8 in our tests here:
Lines 38 to 39 in 4d93652
So, it's not necessary to review PEP8 issues in our PRs as they will get fixed before it gets merged into master.
To validate the components in the callbacks, I think we'll need to pass the component name back in the So, that is, we could modify the Dash API to include and then do a component lookup in the callback decorator |
rmarren1
commented
Aug 20, 2018
^ Definitely, I was going to add this to the next iteration. You don't need this to validate against components in the initial layout, but I don't think there is any other way to validate against dynamically generated components without updating state in the backend after initialization. |
rmarren1
commented
Aug 21, 2018
PR which adds 'type' and 'namespace' to the |
rmarren1
commented
Oct 18, 2018
|
T4rk1n
commented
Oct 18, 2018
Oh ok, I would still integrate with the dev tools so just setting debug=True is required for it. |
Oh I thought you meant something different, yeah it should be disabled in production. |
T4rk1n
commented
Oct 30, 2018
@rmarren1 How would the component as prop validate ? proptype is |
rmarren1
commented
Oct 30, 2018
@T4rk1n There is a custom type called dash/dash/development/base_component.py Lines 380 to 397 in 588ce3d |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
rmarren1
commented
Nov 8, 2018
Closing in favor of #452, which is the same PR but with a more readable commit history. Will link back to here for the relevant discussions. |
Allow tabs null children
PR for #264
Current Prerelease
Validation is on by default. To turn it off, you can set
app.config.disable_component_validation = TrueTest Cases to run for demo
Example Error Messages
PropTypes to Cerberus reference
array{'type': 'list'}bool{'type': 'boolean'}func{}object{'type': 'dict'}dictobject. We cannot be more general (e.g.collections.abc.Mapping) since the coreComponentis an instance of that.string{'type': 'string'}symbol{}node{'anyof': [{'type': 'component'}, {'type': 'boolean'}, {'type': 'number'}, {'type': 'string'}, {'type': 'list', 'schema': {'anyof': [{'type': 'component'}, {'type': 'boolean'}, {'type': 'number'}, {'type': 'string'}]}}]}instanceOf(Object){}oneOf(['val1', 2]){'allowed': [None, 'val1', 2]}'characters stripped off each end. This is becausemetadata.jsongeneration serializes the literal values as json, so for examplePropTypes.oneOf(['News', 'Photos'])serializes to["'News'", "'Photos'"]. reactjs/react-docgen#57oneOfType( [ PropTypes.string, PropTypes.bool ] ){'anyof': [{'type': 'string', 'type': 'boolean'}]}PropTypethat cannot be validated individually (e.g.PropType.func), no validation will occur and the schema will effectively be{}arrayOf( PropTypes.number ){'type': 'list', 'schema': {'type': 'number'}}objectOf( PropTypes.number ){'type': 'dict', 'valueschema': {'type': 'number'}}shape( { k1: PropTypes.string, k2: PropTypes.number } ){'type': 'dict', 'allow_unknown': False, 'schema': {'k1': {'type': 'string}, 'k2': {'type': 'number'}}}any{'type': ('boolean', 'number', 'string', 'dict', 'list')}