Session_state not getting initialized

Hi,

I see this error complaining that one of the session state variable is not initialized.

for idea_str in st.session_state.idea_list:
  File "/usr/local/lib/python3.7/site-packages/streamlit/runtime/state/session_state_proxy.py", line 121, in __getattr__
    raise AttributeError(_missing_attr_error_message(key))
AttributeError: st.session_state has no attribute "idea_list". Did you forget to initialize it? More info: https://docs.streamlit.io/library/advanced-features/session-state#initialization

The session_state is however initialized at the beginning of the code:


if 'idea_list' not in st.session_state:
    st.session_state.idea_list = []

Note that this does not happen always. It happens occasionally and sometimes with other state variables.
Any reason why this is happening?
Is there any limitation on the number of session_state variables?

Thanks

Sudipta

Hey @bhawmik,

Is this a multipage app? Also, what version of Streamlit are you using?

Yes, this is a multipage app. I am using version 1.20

Are you initializing the value on every page? And does this issue persist if you upgrade to the most recent version of Streamlit?

State variable initialization is done at the top of the code block, before entering the pages code:

tab1,tab2,tab3 = st.tabs([“Home”,“Login”,“SignUp”])

NOTE: This is a transient error and does not happen always.

I have not tried v1.25 yet.

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