From 633bcb4dce6db90f0196dd45d5df89821d03a4a0 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 11 Nov 2025 19:09:26 -0600 Subject: [PATCH 1/3] Close #2116. On bookmark, skip serializing input if it yields a SilentException --- shiny/session/_session.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) From e87a4a5ef1678516acbfbdc000b37bc164d37d10 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 14 Nov 2025 18:05:01 -0600 Subject: [PATCH 2/3] Add a playwright test --- tests/playwright/shiny/bookmark/modal/app.py | 9 ++++++++- .../shiny/bookmark/modal/test_bookmark_modal.py | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) 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") From 508cd938317f5225bf15eb9fad7a029749c12c51 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 14 Nov 2025 18:17:14 -0600 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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