In the new version of Streamlit (1.37), it appears that calling st.rerun
inside a try-except
block results in a failure. This issue can be demonstrated using a decorator as an example, where the decorator includes a try-except
block and wraps a function that calls st.rerun
. This behavior does not occur when st.rerun
is called directly within a function without such error handling.
import streamlit as st
import logging
def error_logging_decorator(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
logging.error(f"Error in function {func.__name__}: {e}")
st.error(f"An error occurred: {e}")
raise e # Re-raise the exception
return wrapper
@error_logging_decorator
def decorated_function(): #this will fail
if st.button("Refresh"):
st.rerun()
def plain_function():
if st.button("Refresh"):
st.rerun()
Expected Behavior:
Both the decorated_function
and plain_function
should trigger a rerun when the âRefreshâ button is pressed.
Actual Behavior:
decorated_function
raises an exception and fails to rerun.plain_function
works as expected and triggers a rerun.
Logs:
2024-07-26 13:10:22,773 - admin - ERROR - Error in function decorated_function: RerunData(page_script_hash='d42b4824a51958adffc95194dcc95934', is_fragment_scoped_rerun=True)
streamlit.runtime.scriptrunner.exceptions.RerunException: RerunData(page_script_hash='d42b4824a51958adffc95194dcc95934', is_fragment_scoped_rerun=True)