Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions dash/development/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ def __iter__(self):
for t in self._traverse_ids():
yield t.id # type: ignore[reportAttributeAccessIssue]

def __bool__(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also changes the result of if not self.layout in dash.py:1894. An empty layout with use_pages=True is no longer replaced with page_container, and every request then errors. Can you update that check so an empty component still counts as unset there?

# Without this, truthiness falls back to __len__, so a component
# with no children (or no children prop, like DataTable) is falsy.
return True

def __len__(self):
"""Return the number of items in the tree."""
# TODO - Should we return the number of items that have IDs
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/development/test_base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dash import __version__, Dash
from dash import html
from dash.development.base_component import Component
from dash import dcc, Input, Output
from dash import dcc, dash_table, Input, Output

Component._prop_names = ("id", "a", "children", "style")
Component._type = "TestComponent"
Expand Down Expand Up @@ -539,3 +539,11 @@ def update2(v):
def test_debc030_invalid_children_args():
with pytest.raises(TypeError):
dcc.Input(children="invalid children")


def test_debc031_bool_is_always_true():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This covers bool() itself but not the case that breaks. Can you add a dash_duo test under tests/integration/multi_page/: use_pages=True, app.layout = html.Div(), check that the home page renders? It fails with the current change, so it guards the fix.

assert bool(Component())
assert bool(Component(children=[]))
assert bool(html.Div())
assert bool(dash_table.DataTable(data=[{"a": 1}]))
assert (html.Div() or None) is not None
Loading