-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate component properties #264 - March 1 #452
Conversation
Thanks, I'll have a good look on friday review party. |
@@ -884,6 +894,7 @@ def add_context(*args, **kwargs): | |||
mimetype='application/json' | |||
) | |||
|
|||
self.callback_map[callback_id]['func'] = func |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do that in two difference part ? Couldn't your additions in dispatch be in add_context
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would have to pass namespace
, component_id
, component_property
, to this since that info is available in dispatch
. I originally thought this might clash with the other arguments (e.g. if you had a property called namespace
) although I now think this would be fine, but it might make it difficult if we want to support passing props with keyword arguments in the future.
For the |
Updates:
Bumped all release candidates. |
Tested the RCs with dash-docs, and a few Dash apps I have built. |
|
Testing the demo with the rc version I got a figure validation error and the message:
Is it |
Shouldn't |
I think the graph now put a random id if there's none. |
Wanted to note that the issue I raised in the other thread still exists. Numerical types in checklist values and dropdown values (and probably other components too) still raise errors with the latest release. |
Updated top level comment, the correct way to turn off validation is by setting |
This was a really great effort and was in line to be a PR of the Year 🏆 . In the end, with the addition of alternative language backends for Dash (DashR), we decided to double down on the Dash Dev Tools UI and invest & maintain the validation code in the front-end. |
Note: This PR is a continuation of #340. That PR had ~80 comments (most were outdated and no longer relevant), and 96 commits. This PR is the same code, just more readable.
PR for #264
Current Prerelease
Validation is on by default. To turn it off, you can set
app.config.suppress_validation_exceptions = True
Test Cases to run for demo
Example Error Messages
PropTypes to Cerberus reference
array
{'type': 'list'}
bool
{'type': 'boolean'}
func
{}
object
{'type': 'dict'}
dict
object. We cannot be more general (e.g.collections.abc.Mapping
) since the coreComponent
is 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.json
generation 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'}]}
PropType
that 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')}