Has anyone found that they can’t use the debugger in their streamlit code anymore once they use the native state management? Now whenever I use the debugger, it’s as if it can’t store any data in the st.session_state
object.
When I run the app, the code runs fine. However when I use my debugger in pycharm, I can’t get past the first line that accesses the st.session_state
call because the “dictionary” is empty.
See this example:
print(st.session_state)
{}
st.session_state['foo'] = 'bar'
st.session_state['foo']
Traceback (most recent call last):
File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/streamlit/state/session_state.py", line 381, in __getitem__
return self._getitem(widget_id, key)
File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/streamlit/state/session_state.py", line 424, in _getitem
raise KeyError
KeyError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3457, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-9404e5a9ae15>", line 1, in <module>
st.session_state['foo']
File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/streamlit/state/session_state.py", line 666, in __getitem__
return state[key]
File "/opt/anaconda3/envs/yogen2/lib/python3.7/site-packages/streamlit/state/session_state.py", line 383, in __getitem__
raise KeyError(_missing_key_error_message(key))
KeyError: 'st.session_state has no key "foo". Did you forget to initialize it? More info: https://docs.streamlit.io/library/advanced-features/session-state#initialization'
print(st.session_state)
{}
How are we supposed to develop applications if we can’t use the debugger mode in our IDEs?