diff --git a/CHANGELOG.md b/CHANGELOG.md index 50041a08d..ec855342a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fixed `ui.tooltip()`'s `options` parameter to properly pass Bootstrap tooltip options to the underlying web component. (#2101) +* Fixed an issue where `session.bookmark()` would error when non-existent `input` values are read. (#2117) + * Revised `accordion()`'s `open` logic to close all panels when an empty list is passed. (#2109) ## [1.5.0] - 2025-09-11 diff --git a/shiny/session/_session.py b/shiny/session/_session.py index f13a970b3..ed1fc876b 100644 --- a/shiny/session/_session.py +++ b/shiny/session/_session.py @@ -1477,7 +1477,11 @@ async def _serialize( continue if key in exclude_set: continue - val = value() + + try: + val = value() + except SilentException: + continue # Possibly apply custom serialization given the input id serializer = self._serializers.get(key, serializer_default) diff --git a/tests/playwright/shiny/bookmark/modal/app.py b/tests/playwright/shiny/bookmark/modal/app.py index 68f66c4f3..4e3a97bcc 100644 --- a/tests/playwright/shiny/bookmark/modal/app.py +++ b/tests/playwright/shiny/bookmark/modal/app.py @@ -9,12 +9,19 @@ def app_ui(request: Request): ) -def server(input: Inputs, ouput: Outputs, session: Session): +def server(input: Inputs, output: Outputs, session: Session): @reactive.effect @reactive.event(input.letter, ignore_init=True) async def _(): await session.bookmark() + # Just to make sure that missing inputs don't break bookmarking + # behavior (https://github.com/posit-dev/py-shiny/pull/2117) + @reactive.effect + @reactive.event(input.non_existent_input) + def _(): + pass + app = App(app_ui, server, bookmark_store="url") diff --git a/tests/playwright/shiny/bookmark/modal/test_bookmark_modal.py b/tests/playwright/shiny/bookmark/modal/test_bookmark_modal.py index e3d8fbf41..555f84fa9 100644 --- a/tests/playwright/shiny/bookmark/modal/test_bookmark_modal.py +++ b/tests/playwright/shiny/bookmark/modal/test_bookmark_modal.py @@ -19,3 +19,4 @@ def test_bookmark_modules(page: Page, local_app: ShinyAppProc): ) assert "?" not in page.url + assert "An error has occurred" not in page.inner_text("body")