Repository navigation
Fix IndexError building a single-select selector with no options - #1849
Merged
petar-qb merged 3 commits intoAug 31, 2026
Merged
Conversation
get_dict_options_and_value derived the single-select default value as list_values[0] with no empty guard. options default to [] on RadioItems, Dropdown and Checklist, so building a single-select selector without options (RadioItems().build(), Dropdown(multi=False).build()) raised IndexError. Fall back to None when there is nothing to select. Multi-select already returned the empty list, and populated selectors are unchanged.
winklemad
requested review from
Joseph-Perkins,
antonymilne,
huong-li-nguyen,
lingyielia and
maxschulz-COL
as code owners
August 31, 2026 01:59
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Pull request overview
Fixes an IndexError when building single-select categorical selectors with empty options by ensuring a safe default value is used, and adds regression tests to prevent reintroducing the crash.
Changes:
- Update
get_dict_options_and_valueto returnNoneas the default single-select value whenoptionsis empty. - Add unit tests covering empty-options builds for
RadioItemsand single-selectDropdown. - Add a changelog entry describing the fix.
File summaries
| File | Description |
|---|---|
| vizro-core/src/vizro/models/_components/form/_form_utils.py | Guard single-select default value derivation for empty options to avoid IndexError. |
| vizro-core/tests/unit/vizro/models/_components/form/test_radio_items.py | Add regression test asserting empty-options RadioItems.build() returns value=None. |
| vizro-core/tests/unit/vizro/models/_components/form/test_dropdown.py | Add regression test asserting empty-options single-select Dropdown.build() returns value=None. |
| vizro-core/changelog.d/20260831_120000_winklemad.md | Document the crash fix in the changelog. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
petar-qb
approved these changes
Aug 31, 2026
petar-qb
left a comment
Contributor
There was a problem hiding this comment.
Great as always @winklemad! 🚀 Thanks for another contribution 😃
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Building a single-select selector with no options raised
IndexError:optionsdefaults to[]onRadioItems,DropdownandChecklist, so a default-constructed single-select selector hits this.get_dict_options_and_valuederived the single-select default value aslist_values[0]with no empty guard; it now falls back toNonewhen there is nothing to select. Multi-select already returned the empty list, and populated selectors are unchanged.Added
test_radio_items_build_empty_optionsandtest_dropdown_build_empty_options_single(both fail onmainwithIndexError, pass with this change).Screenshot
n/a (crash fix)
Notice
I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":