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

st.chat_input() not resetting to None after script rerun #7629

Closed
4 tasks done
jeffkayne opened this issue Oct 30, 2023 · 4 comments
Closed
4 tasks done

st.chat_input() not resetting to None after script rerun #7629

jeffkayne opened this issue Oct 30, 2023 · 4 comments
Assignees
Labels
priority:P1 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working

Comments

@jeffkayne
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

Hi guys,

Since streamlit>=1.28.0, there is unexpected behaviour in my streamlit chat app. I have looked at the 1.28.0 commits but haven't spotted anything... The new version seems to not reset the output of st.chat_input() after rerunning the app with st.rerun() or st.experimentatl_rerun(). This causes an RecursionError: maximum recursion depth exceeded while calling a Python object in the app. See code below.

Reproducible Code Example

import streamlit as st

prompt = st.chat_input()
print(prompt)

if prompt:
    st.rerun()

Steps To Reproduce

  1. Run the app above
  2. Enter a message in the chat input and hit enter

Expected Behavior

After the st.rerun(), I expect the script to rerun, resetting the st.chat_input() and therefore making prompt = None.

Current Behavior

After the st.rerun(), there is an infinite loop, making an error:

RecursionError: maximum recursion depth exceeded while calling a Python object

Is this a regression?

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

Debug info

  • Streamlit version: 1.28.0
  • Python version: 3.10.12
  • Operating System: MacOs 13.5.1
  • Browser: Chrome

Additional Information

--> Additional info into why I'm using st.rerun() in this context:
I maintain the streamlit-feedback component, which requires the use of st.rerun() to load the most recent feedback component for a chat message. An example of this implementation can be seen here.

@jeffkayne jeffkayne added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Oct 30, 2023
@github-actions
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

@ghz
Copy link

ghz commented Oct 30, 2023

The same with a simple conditionnal button scenario.

Even the example code from the doc doesn't work anymore for egg :

import streamlit as st

if "value" not in st.session_state:
    st.session_state.value = "Title"

st.header(st.session_state.value)

if st.button("Foo"):
    st.session_state.value = "Foo"
    st.rerun()

The on_click fallback seems not affected. This code doesn't provoke any infinite loops :

import streamlit as st

if "value" not in st.session_state:
    st.session_state.value = "Title"

st.header(st.session_state.value)

def callback_fn():
    st.session_state.value = "Foo"
    st.rerun()

st.button("Foo", on_click=callback_fn)

@vdonato vdonato added status:confirmed Bug has been confirmed by the Streamlit team priority:P0 and removed status:needs-triage Has not been triaged by the Streamlit team labels Oct 31, 2023
@AnOctopus
Copy link
Contributor

I think I know the cause. As part of session state yield points, I allowed triggers to no longer be reset if the script run was interrupted by a rerun exception, to bring it in line with the behavior of fast reruns. But I neglected to account for st.rerun also causing a rerun exception, and it makes more sense to treat reruns triggered that way as being script run completions. We should have this fixed in a patch release soon.

@vdonato
Copy link
Collaborator

vdonato commented Nov 1, 2023

Closing this issue as this was addressed by #7643. We'll have the changes released in a patch release tomorrow or Friday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:P1 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