Waiting for iteration on a loop

i need this code to wait for each iteration

Import python packages

import streamlit as st
from snowflake.snowpark.context import get_active_session
import pandas as pd

def update_approval_status(user_name,role_name,approval_status):
# Execute a SQL query to fetch column values
query = f"update TDW_D.CONTROL.SNOWFLAKE_ACCESS_LOG set APPROVAL_STATUS=True where USER_NAME = {user_name} and REQUESTED_ROLE = {role_name} and GRANT_ACTIVITY is null"

if ‘counter1’ not in st.session_state:
st.session_state.counter1 = 0

if st.button(“Approve Access”) and counter1>0:
for _ in range(counter):
user_name = user_options_df[‘USER_NAME’].tolist()[counter1-1]
role_name = role_options_df[‘REQUESTED_ROLE’].tolist()[counter1-1]


    approval_status = st.selectbox(
    f"Do you want to provide the role '{role_name}' to user '{user_name}'?",
    ("Yes", "No")

    # Display the approval and rejection buttons
    approve_button = st.button(f"Approve Access - {st.session_state.counter1}")
    reject_button = st.button(f"Reject Access - {st.session_state.counter1}")

    # Use a checkbox to wait for user input
    if approve_button and approval_status == "Yes":
        # Perform the approval action for the specific user and role
        update_approval_status(user_name, role_name, True)
        st.success(f"Access approved for user '{user_name}' with role '{role_name}'.")
        # Decrease the counter for the next iteration
        counter1 = counter1 - 1
        st.session_state.counter1 += 1
    elif reject_button:
        # Perform the rejection action if needed
        update_approval_status(user_name, role_name, False)
        st.warning(f"Access rejected for user '{user_name}' with role '{role_name}'.")
        # Decrease the counter for the next iteration
        counter1 = counter1 - 1
        st.session_state.counter1 += 1
    if counter1==0:
    # Display a message when all approvals are completed
        st.success("All access approvals have been processed.")

Receiving error:

DuplicateWidgetID: There are multiple identical st.selectbox widgets with the same generated key.

When a widget is created, it’s assigned an internal key based on its structure. Multiple widgets with an identical structure will result in the same internal key, which causes this error.

To fix this error, please pass a unique key argument to st.selectbox.


File "/home/udf/297048528442374/streamlit_app.py", line 128, in <module>
    approval_status = st.selectbox(

Hi @gmorla,

Could you please make sure to edit your post so that your code is formatted properly?

At a glance, it looks like you could resolve this by making sure each widget has a unique key, which you could do in your loop by doing something like this:

for i in range(counter):
    status = st.selectbox(..., key=f"status_{i}")
    approve = st.button(..., key=f"approve_{i}")

If that doesn’t work, could you please edit your post down to a small reproducible script that shows that you’re trying to do, and doesn’t work? If you want others to be able to provide help, then please simplify your script to not require any access to your database to test it.