Skip to content

Commit 1e56b56

Browse files
committed
fix: pass dropdown label key (not value) to mo.ui.dropdown value= init param
When options is a dict {label: value}, Marimo validates value= against the dict keys (labels), not the values. _rebuild_database_pick was passing a database ID (dict value) which raised ValueError on startup. Now resolves the label key corresponding to the previously-selected ID instead.
1 parent b1f9d5c commit 1e56b56

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

hotdata_marimo/databases.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,15 @@ def _rebuild_database_pick(self) -> None:
128128
)
129129
return
130130
options = {db.description or db.id: db.id for db in dbs}
131-
value = current if current in options.values() else next(iter(options.values()))
131+
# current holds the previously selected database ID (.value returns the dict value).
132+
# mo.ui.dropdown validates value= against option keys (labels), not values.
133+
default_key = next(iter(options))
134+
selected_key = next((k for k, v in options.items() if v == current), default_key)
132135
self.database = mo.ui.dropdown(
133136
options=options,
134137
label="Database",
135138
full_width=True,
136-
value=value,
139+
value=selected_key,
137140
)
138141

139142
def _maybe_create(self) -> None:

0 commit comments

Comments
 (0)