Request_rerun() function

Hello, I have a question regarding rerunning my streamlit app.
I have been using streamlit v0.72.0 with no problems, but when I upgrade to v1.3.0 I get the following error:

TypeError: request_rerun() missing 1 required positional argument: ‘client_state’

I am not really sure what it means, but this occurs when I call the “sync” function from the class below:

class SessionState:

def __init__(self, session, hash_funcs):
    """Initialize SessionState instance."""
    self.__dict__["_state"] = {
        "data": {},
        "hash": None,
        "hasher": streamlit.legacy_caching.hashing._CodeHasher(hash_funcs),
        "is_rerun": False,
        "session": session,
    }

def __call__(self, **kwargs):
    """Initialize state data once."""
    for item, value in kwargs.items():
        if item not in self._state["data"]:
            self._state["data"][item] = value

def __getitem__(self, item):
    """Return a saved state value, None if item is undefined."""
    return self._state["data"].get(item, None)

def __getattr__(self, item):
    """Return a saved state value, None if item is undefined."""
    return self._state["data"].get(item, None)

def __setitem__(self, item, value):
    """Set state value."""
    self._state["data"][item] = value

def __setattr__(self, item, value):
    """Set state value."""
    self._state["data"][item] = value

def clear(self):
    """Clear session state and request a rerun."""
    self._state["data"].clear()
    self._state["session"].experimental_rerun()

def sync(self):
    """Rerun the app with all state values up to date from the beginning to fix rollbacks."""

    # Ensure to rerun only once to avoid infinite loops
    # caused by a constantly changing state value at each run.
    #
    # Example: state.value += 1
    if self._state["is_rerun"]:
        self._state["is_rerun"] = False

    elif self._state["hash"] is not None:
        if self._state["hash"] != self._state["hasher"].to_bytes(self._state["data"], None):
            self._state["is_rerun"] = True
            self._state["session"].experimental_rerun()

    self._state["hash"] = self._state["hasher"].to_bytes(self._state["data"], None)

As I said this works perfectly fine in v.0.72.0 and only occurs when I upgrade.
Any help would be greatly appreciated.

Any ideas on this one please?

Hey @apol96,

So Streamlit launched an internal st.session_state in version 0.84, and I have a seeking suspicion that the old class SessionState workaround will no longer work when you upgrade the Streamlit version

I imagine that you will need to update your code to use the new st.session_state feature or to pin your version to 0.83.

Happy Streamlit-ing!
Marisa

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.