Skip to content

fixed validation_layout in pages #2182

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

Merged
merged 8 commits into from
Sep 8, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Fixed

- [#2182](https://github.com/plotly/dash/pull/2182) Fix [#2172](https://github.com/plotly/dash/issues/2172) Make it so that when using pages, if `suppress_callback_exceptions=True` the `validation_layout` is not set.
- [#2152](https://github.com/plotly/dash/pull/2152) Fix bug [#2128](https://github.com/plotly/dash/issues/2128) preventing rendering of multiple components inside a dictionary.
- [#2187](https://github.com/plotly/dash/pull/2187) Fix confusing error message when trying to use pytest fixtures but `dash[testing]` is not installed.
- [#2202](https://github.com/plotly/dash/pull/2202) Fix bug [#2185](https://github.com/plotly/dash/issues/2185) when you copy text with multiple quotes into a table
Expand Down
29 changes: 15 additions & 14 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -2075,20 +2075,21 @@ def update(pathname, search):
_validate.validate_registry(_pages.PAGE_REGISTRY)

# Set validation_layout
self.validation_layout = html.Div(
[
page["layout"]() if callable(page["layout"]) else page["layout"]
for page in _pages.PAGE_REGISTRY.values()
]
+ [
# pylint: disable=not-callable
self.layout()
if callable(self.layout)
else self.layout
]
)
if _ID_CONTENT not in self.validation_layout:
raise Exception("`dash.page_container` not found in the layout")
if not self.config.suppress_callback_exceptions:
self.validation_layout = html.Div(
[
page["layout"]() if callable(page["layout"]) else page["layout"]
for page in _pages.PAGE_REGISTRY.values()
]
+ [
# pylint: disable=not-callable
self.layout()
if callable(self.layout)
else self.layout
]
)
if _ID_CONTENT not in self.validation_layout:
raise Exception("`dash.page_container` not found in the layout")

# Update the page title on page navigation
self.clientside_callback(
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/multi_page/test_pages_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def get_app(path1="/", path2="/layout2"):


def test_pala001_layout(dash_duo):

dash_duo.start_server(get_app())
app = get_app()
dash_duo.start_server(app)

# test layout and title for each page in `page_registry` with link navigation
for page in dash.page_registry.values():
Expand Down Expand Up @@ -93,6 +93,9 @@ def test_pala001_layout(dash_duo):
dash_duo.wait_for_page(url=f"http://localhost:{dash_duo.server.port}/find_me")
dash_duo.wait_for_text_to_equal("#text_not_found_404", "text for not_found_404")

# test `validation_layout` exists when suppress_callback_exceptions=False`
assert app.validation_layout is not None

assert dash_duo.get_logs() == [], "browser console should contain no error"
# dash_duo.percy_snapshot("pala001_layout")

Expand Down
5 changes: 4 additions & 1 deletion tests/integration/multi_page/test_pages_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def test_paor001_order(dash_duo):

app = Dash(__name__, use_pages=True)
app = Dash(__name__, use_pages=True, suppress_callback_exceptions=True)

dash.register_page(
"multi_layout1",
Expand Down Expand Up @@ -64,4 +64,7 @@ def test_paor001_order(dash_duo):
list(dash.page_registry) == modules
), "check order of modules in dash.page_registry"

# There should be no `validation_layout` when suppress_callback_exceptions=True`
assert app.validation_layout is None

assert dash_duo.get_logs() == [], "browser console should contain no error"