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

Make shallow copies of options returned from ensure_indexable #8064

Merged
merged 1 commit into from Feb 2, 2024

Conversation

vdonato
Copy link
Collaborator

@vdonato vdonato commented Feb 2, 2024

The strange behavior in #7534 is caused by us saving a reference to the options object into the
*Serde class of an options widget. This causes any mutations to that object to cause weird side
effects in the next script run.

To avoid this, we return a shallow copy of every object passed into ensure_indexable either
by calling copy.copy (for already indexable objects) or by converting the object into a list
(for non-indexable objects).

There's some chance that making this change may have unintended side effects in some apps
that somehow rely on the current behavior, so we should probably do some testing to see if we
can catch any of these cases before this PR lands in a release. Most likely, though, we'll be willing
to bend SemVer conventions and break any existing apps to make this fix because the current
behavior is quite strange/unintuitive.

Closes #7534

lib/streamlit/type_util.py Outdated Show resolved Hide resolved
@vdonato vdonato merged commit 3bf4284 into develop Feb 2, 2024
39 checks passed
@vdonato vdonato deleted the vdonato/fix/7534 branch February 2, 2024 23:40
zyxue pushed a commit to zyxue/streamlit that referenced this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong session state for st.selectbox
2 participants