You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have provided sufficient information below to help reproduce this issue.
Summary
In regular Streamlit, the options argument of a selectbox can be any iterable, as long as there is a format_func provided to go from the item type to a string.
However, testing.v1.element_tree contains the function:
@propertydefindex(self) ->int|None:
"""The index of the current selection. (int)"""ifself.valueisNone:
returnNoneiflen(self.options) ==0:
return0returnself.options.index(str(self.value))
What ends up happening here is that self.value is of the type of the actual element (populated during the first call to run(), and self.options is a list of strings. As a result, Python raises an error because the value is not in the list of options.
(the example is contrived for simplicity: more likely you'd do something like at.text_input("some_element").input("boo").run())
Steps To Reproduce
No response
Expected Behavior
Either options should be a list of Foo (this seems more sensible to me), or value should be the formatted string
Current Behavior
self=Selectbox(_value=InitialValue(), label='foo', options=['bar', 'baz'])
@propertydefindex(self) ->int|None:
"""The index of the current selection. (int)"""ifself.valueisNone:
returnNoneiflen(self.options) ==0:
return0>returnself.options.index(str(self.value))
EValueError: "Foo(name='bar')"isnotinlist
../../mambaforge/envs/dlf-ui/lib/python3.10/site-packages/streamlit/testing/v1/element_tree.py:930: ValueError
Is this a regression?
Yes, this used to work in a previous version.
Debug info
Streamlit version: 1.28.0
Python version: 3.10.8
Operating System:
Browser: AppTest
Additional Information
No response
The text was updated successfully, but these errors were encountered:
## Describe your changes
Fixes issues with selecting items in widgets when `format_func` is used,
by storing the `format_func` in session state during app tests and using
it to convert the provided values into the ones stored by the protobuf.
## GitHub Issue Link (if applicable)
#7679 and #8019
## Testing Plan
App tests added
## Describe your changes
Fixes issues with selecting items in widgets when `format_func` is used,
by storing the `format_func` in session state during app tests and using
it to convert the provided values into the ones stored by the protobuf.
## GitHub Issue Link (if applicable)
streamlit#7679 and streamlit#8019
## Testing Plan
App tests added
Checklist
Summary
In regular Streamlit, the
options
argument of a selectbox can be any iterable, as long as there is aformat_func
provided to go from the item type to a string.However,
testing.v1.element_tree
contains the function:What ends up happening here is that
self.value
is of the type of the actual element (populated during the first call torun()
, andself.options
is a list of strings. As a result, Python raises an error because the value is not in the list of options.Reproducible Code Example
(the example is contrived for simplicity: more likely you'd do something like
at.text_input("some_element").input("boo").run()
)Steps To Reproduce
No response
Expected Behavior
Either
options
should be a list ofFoo
(this seems more sensible to me), orvalue
should be the formatted stringCurrent Behavior
Is this a regression?
Debug info
Additional Information
No response
The text was updated successfully, but these errors were encountered: