Skip to content

Commit a8f5217

Browse files
authored
fix(bookmark): skip serializing input if it yields a SilentException (#2117)
1 parent 6ac04b8 commit a8f5217

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
* Fixed `ui.tooltip()`'s `options` parameter to properly pass Bootstrap tooltip options to the underlying web component. (#2101)
1717

18+
* Fixed an issue where `session.bookmark()` would error when non-existent `input` values are read. (#2117)
19+
1820
* Revised `accordion()`'s `open` logic to close all panels when an empty list is passed. (#2109)
1921

2022
## [1.5.0] - 2025-09-11

shiny/session/_session.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,11 @@ async def _serialize(
14771477
continue
14781478
if key in exclude_set:
14791479
continue
1480-
val = value()
1480+
1481+
try:
1482+
val = value()
1483+
except SilentException:
1484+
continue
14811485

14821486
# Possibly apply custom serialization given the input id
14831487
serializer = self._serializers.get(key, serializer_default)

tests/playwright/shiny/bookmark/modal/app.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ def app_ui(request: Request):
99
)
1010

1111

12-
def server(input: Inputs, ouput: Outputs, session: Session):
12+
def server(input: Inputs, output: Outputs, session: Session):
1313

1414
@reactive.effect
1515
@reactive.event(input.letter, ignore_init=True)
1616
async def _():
1717
await session.bookmark()
1818

19+
# Just to make sure that missing inputs don't break bookmarking
20+
# behavior (https://github.com/posit-dev/py-shiny/pull/2117)
21+
@reactive.effect
22+
@reactive.event(input.non_existent_input)
23+
def _():
24+
pass
25+
1926

2027
app = App(app_ui, server, bookmark_store="url")

tests/playwright/shiny/bookmark/modal/test_bookmark_modal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ def test_bookmark_modules(page: Page, local_app: ShinyAppProc):
1919
)
2020

2121
assert "?" not in page.url
22+
assert "An error has occurred" not in page.inner_text("body")

0 commit comments

Comments
 (0)