Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: st.session_state has no attribute "last_time". #33

Open
rawmean opened this issue May 12, 2023 · 2 comments
Open

AttributeError: st.session_state has no attribute "last_time". #33

rawmean opened this issue May 12, 2023 · 2 comments

Comments

@rawmean
Copy link

rawmean commented May 12, 2023

I get the following error:

AttributeError: st.session_state has no attribute "last_time". Did you forget to initialize it? More info: https://docs.streamlit.io/library/advanced-features/session-state#initialization

It comes from this line. The fix seems to be easy (avoid using the dot notation when the key doesn't exist)

    if "last_time" not in st.session_state:
        st.session_state.last_time = datetime.datetime.now()
    _track_user()
@nbora0911
Copy link

@rawmean How did you patch this in your code without streamlit-analytics having pushed it?

@rawmean
Copy link
Author

rawmean commented Feb 15, 2024

@rawmean How did you patch this in your code without streamlit-analytics having pushed it?
Try this:
'''
if "last_time" not in st.session_state:
st.session_state[last_time] = datetime.datetime.now()
_track_user()
'''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants