Skip to content
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

[BUG] Children prop is not always validated #1348

Closed
jdamiba opened this issue Jul 30, 2020 · 1 comment
Closed

[BUG] Children prop is not always validated #1348

jdamiba opened this issue Jul 30, 2020 · 1 comment
Labels
good first issue suitable for newcomers

Comments

@jdamiba
Copy link

jdamiba commented Jul 30, 2020

moved from https://github.com/plotly/dash-core/issues/214

@alexcjohnson

I would expect the Dash app that follows to throw an error when the dcc.Input component tries to set children={"a dict": "is not allowed for children-input"}.

However, the error is only thrown when the html.Div component attempts to do the same.

import dash
import dash_html_components as html
import dash_core_components as dcc


app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Input(children={"a dict": "is not allowed for children-input"}),
    html.Div(children={"a dict": "is not allowed for children-div"})

])

if __name__ == '__main__':
    app.run_server(debug=True)

Error:

An object was provided as `children` instead of a component, string, or number (or list of those). Check the children property that looks something like:
{
  "a dict": "is not allowed for children-div"
}
@chriddyp chriddyp added the good first issue suitable for newcomers label Sep 22, 2020
@alstn2468
Copy link
Contributor

I think it is a little more right raise unexpected keyword argument: children error .
The reason seems to be that the __init__ function was called with children missing from args in the generated file.

  • dash/development/base_component.py (134-141)
if not k_in_propnames and not k_in_wildcards:
    allowed_args = ", ".join(
        sorted(self._prop_names)
    )  # pylint: disable=no-member
    raise TypeError(
        f"{error_string_prefix} received an unexpected keyword argument: `{k}`"
        f"\nAllowed arguments: {allowed_args}"
   )
  • Input.py
args = {k: _locals[k] for k in _explicit_args if k != "children"}
for k in []:
    if k not in args:
        raise TypeError("Required argument `" + k + "` was not specified.")
super(Input, self).__init__(**args)
  • Link.py
args = {k: _locals[k] for k in _explicit_args if k != "children"}
for k in ["href"]:
    if k not in args:
        raise TypeError("Required argument `" + k + "` was not specified.")
super(Link, self).__init__(children=children, **args)

Is there a reason for separately pass children?
If put children in args together, the validation will be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue suitable for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants