St.session_state has no key "$$WIDGET_ID-e793ab4d3b6b8db3f8c2....."


I need help when I use st.session_state

Steps to reproduce

KeyError: ‘st.session_state has no key “$$WIDGET_ID-e793ab4d3b6b8db3f8c2d0be20452459-None”. Did you forget to initialize it? More info: Add statefulness to apps - Streamlit Docs


File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/", line 548, in _run_script
    self._session_state.on_script_will_rerun(rerun_data.widget_states)File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/streamlit/runtime/state/", line 68, in on_script_will_rerun
    self._state.on_script_will_rerun(latest_widget_states)File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/streamlit/runtime/state/", line 482, in on_script_will_rerun
    self._compact_state()File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/streamlit/runtime/state/", line 300, in _compact_state
    self._old_state[key_or_wid] = self[key_or_wid]
                                  ~~~~^^^^^^^^^^^^File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/streamlit/runtime/state/", line 380, in __getitem__
    raise KeyError(_missing_key_error_message(key))

Code snippet:

add code here

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

Explain what you expect to happen when you run the code above.

Actual behavior:

Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.

Debug info

  • Streamlit version: (get it with $ streamlit version)
  • Python version: (get it with $ python --version)
  • Using Conda? PipEnv? PyEnv? Pex?
  • OS version:
  • Browser version:

Requirements file

Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.


  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.

Hey @Hangjun_Ji,

Thanks for sharing this question. Can you please share a code snippet from your app that will enable us to reproduce this error?