Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local app testing - selectbox format_func erroring out when using key #8019

Closed
3 of 4 tasks
sfc-gh-melnacouzi opened this issue Jan 25, 2024 · 2 comments
Closed
3 of 4 tasks
Labels
feature:app-testing priority:P3 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working

Comments

@sfc-gh-melnacouzi
Copy link

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

If in your streamlit, there is a selectbox with format_func (returning a value different from the key), then we get the following error with streamlit app testing:

ValueError: 'key1' is not in list

I believe at.selectbox allows you to only select the displayed value (formatted), but you can't select by key.
Not sure if this is intended, but it does seem a bit counter-intuitive.

Reproducible Code Example

from streamlit.testing.v1 import AppTest
import pytest as pytest

def some_streamlit():
    import streamlit as st
    key_to_value = {'key1': 'value1', 'key2': 'value2'}
    st.selectbox('Select Value', key_to_value.keys(), format_func=lambda key: key_to_value[key], key='test')

def test_selectbox():
    at = AppTest.from_function(some_streamlit)
    at.run()
    at.selectbox('test').select('value1').run() # this works
    at.selectbox('test').select('key1').run() # this does not work
    assert not at.exception

Steps To Reproduce

No response

Expected Behavior

No response

Current Behavior

No response

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version:
  • Python version:
  • Operating System:
  • Browser:

Additional Information

No response

@sfc-gh-melnacouzi sfc-gh-melnacouzi added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Jan 25, 2024
Copy link

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

@sfc-gh-jcarroll
Copy link
Collaborator

sfc-gh-jcarroll commented Jan 27, 2024

cc @AnOctopus - reported in Snowflake usage, I think this might be a duplicate of #7679 ? Or certainly related.

@sfc-gh-jcarroll sfc-gh-jcarroll added priority:P3 status:confirmed Bug has been confirmed by the Streamlit team and removed status:needs-triage Has not been triaged by the Streamlit team labels Jan 27, 2024
AnOctopus added a commit that referenced this issue Mar 7, 2024
## 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
zyxue pushed a commit to zyxue/streamlit that referenced this issue Apr 16, 2024
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:app-testing priority:P3 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants