444B / streamlit-analytics2

👀 Track & visualize user interactions with your streamlit app
MIT License
14 stars 2 forks source link

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

Closed 444B closed 4 months ago

444B commented 4 months ago

Original issue by rawmean on 2023-05-12 02:08:34+00:00

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()
444B commented 4 months ago

Comment by nbora0911 on 2024-02-15 14:31:35+00:00

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

444B commented 4 months ago

Comment by rawmean on 2024-02-15 18:15:15+00:00

@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() '''

444B commented 4 months ago

@rawmean @nbora0911 is this still relevant?

444B commented 4 months ago

Investigated, found that st.session_state.last_time is the correct method for setting the last time of session state. Could have been related to previous code that got fixed but this seems to be WAI image