Form_submit_button's on_click being called before clicking

Hi everyone,

Following Streamlit’s documentation, I’ve created a form to receive some input and I would like to use the result of such input on the next steps of the app once the submit button is clicked. So, I’ve called a function to save some variables in session state using the ‘on_click’ callback as depicted in the code below:

with st.form(key="filtering_form_{}".format(step)):
    st.subheader("Raw Data Sample")
    st.write(useful_threats[BASIC_ATTRIBUTES].sample(20))

    available_threat_types = f_utils.get_sorted_feat_unique_vals(useful_threats,'threat_type')

    chosen_threat_type = st.selectbox(
        "Which threat type do you want to analyze?", 
        available_threat_types
    )

    st.form_submit_button(
        label="Filter Threats",
        on_click=w_utils.set_step_vars(
            {"filtered": True,
             "threat_type": chosen_threat_type},
            step
        ),
    )

The problem I’m facing is: when I first load the application, without even clicking the form submit button, the ‘on_click’ callback button is executed (I think it happens at widget rendering time) and the variables get set on session state before they should. This misleads the application control flow and thus it behaves incorrectly.

Am I doing something wrong? Is this a known issue?
How should I proceed to make sure the code inside ‘on_click’ callback is only executed on button click?