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

Fixes 'AttributeError' when layout is a function that returns a list of components in dash layout setter #2915

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- [#2896](https://github.com/plotly/dash/pull/2896) The tabIndex parameter of Div can accept number or string type. Fixes [#2891](https://github.com/plotly/dash/issues/2891)
- [#2900](https://github.com/plotly/dash/pull/2900) Allow strings in layout list. Fixes [#2890](https://github.com/plotly/dash/issues/2890)
- [#2908](https://github.com/plotly/dash/pull/2908) Fix when environment variables are ignored by Dash.run() at runtime. Fixes [#2902](https://github.com/plotly/dash/issues/2902)
- [#2915](https://github.com/plotly/dash/pull/2915) Fix 'AttributeError' when layout is a function that returns a list of components. Fixes [#2905](https://github.com/plotly/dash/issues/2905)

## [2.17.1] - 2024-06-12

Expand Down
26 changes: 2 additions & 24 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,32 +713,10 @@ def layout(self, value):
and not self.validation_layout
and not self.config.suppress_callback_exceptions
):

def simple_clone(c, children=None):
cls = type(c)
# in Py3 we can use the __init__ signature to reduce to just
# required args and id; in Py2 this doesn't work so we just
# empty out children.
sig = getattr(cls.__init__, "__signature__", None)
props = {
p: getattr(c, p)
for p in c._prop_names # pylint: disable=protected-access
if hasattr(c, p)
and (
p == "id" or not sig or sig.parameters[p].default == c.REQUIRED
)
}
if props.get("children", children):
props["children"] = children or []
return cls(**props)


layout_value = self._layout_value()
_validate.validate_layout(value, layout_value)
self.validation_layout = simple_clone(
# pylint: disable=protected-access
layout_value,
[simple_clone(c) for c in layout_value._traverse_ids()],
)
self.validation_layout = layout_value

@property
def index_string(self):
Expand Down