Skip to content

Add reproduction for issue #15618: selectbox reverts with format_func + custom classes#62

Merged
sfc-gh-lwilby-1 merged 1 commit into
mainfrom
cursor/selectbox-format-func-revert-eb18
Jun 17, 2026
Merged

Add reproduction for issue #15618: selectbox reverts with format_func + custom classes#62
sfc-gh-lwilby-1 merged 1 commit into
mainfrom
cursor/selectbox-format-func-revert-eb18

Conversation

@sfc-gh-lwilby-1

@sfc-gh-lwilby-1 sfc-gh-lwilby-1 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a reproduction app and detailed investigation notes for streamlit/streamlit#15618 under issues/gh-15618/ (app.py + NOTES.md).

Reproduction status

Bug confirmed and root-caused on current develop (Streamlit 1.58.0).

  • Occurs for frozen dataclasses and plain classes (not just plain classes); value-based __hash__/__eq__ does not prevent it.
  • NamedTuple is immune.
  • Removing the dict lookup from format_func avoids it.

Root cause

The widget state is correct ("two"), but st.selectbox() returns the default option ("one") to the script. validate_and_sync_value_with_options validates the stored selection by calling the user's format_func on it inside a broad except Exception. The stored value is a deepcopy of an instance of the previous rerun's class object (the script redefines the class each run); a dataclass's class-gated __eq__ makes x[s] raise KeyError, which the broad except treats as "value not in options" and resets to index 0. NamedTuple uses value-based tuple.__eq__, so its lookup never raises.

See issues/gh-15618/NOTES.md for the full trace and a suggested fix direction.

Open in Web Open in Cursor 

… + custom classes

Co-authored-by: Laura Wilby <sfc-gh-lwilby-1@users.noreply.github.com>
@sfc-gh-lwilby-1 sfc-gh-lwilby-1 marked this pull request as ready for review June 17, 2026 15:34
@sfc-gh-lwilby-1 sfc-gh-lwilby-1 merged commit fb4af65 into main Jun 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants