streamlit / streamlit

Streamlit — A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
33.1k stars 2.89k forks source link

MediaFileHandler: Missing file for st.dowload_button embedded in st.experimental_fragment #8932

Open dwvisser opened 1 week ago

dwvisser commented 1 week ago

Checklist

Summary

When I run the code example given, and click the Download buttons in rapid succession, I almost always get a missed download and a MediaFileHandler: Missing file message logged.

Reproducible Code Example

import streamlit as st

st.title("Fragment Download")

@st.experimental_fragment()
def dl_button(file: int):
    filename = f"{file}.pdf"
    with open(filename, "rb") as f:
        st.download_button(
            label=f"Download {filename}",
            data=f,
            file_name=filename,
        )

for ix in range(10):
    dl_button(ix)

Steps To Reproduce

  1. Populate the folder containing the given Streamlit app.py with 10 unique PDF files, named 0.pdf through 9.pdf.
  2. streamlit run app.py
  3. Click the first button, then the 2nd button, then the 3rd, etc., without pausing, but you don't necessarily need to do it very fast.

Expected Behavior

I expect every download to succeed. Removing @st.experimental_fragment fixes to where they do succeed, but in our application, the @st.experimental_fragment is otherwise useful for app performance.

Current Behavior

More often than not, at least one of the Download buttons will fail to download (Chrome & Edge show "Couldn't Download xxx in UI", while Firefox just opens a blank tab). A message similar to the following is logged:

2024-06-18 14:39:34.602 MediaFileHandler: Missing file 0ab6ea69b3c422b32dd59acb39a7e2818512c1682364c987b183bac7.bin

Is this a regression?

Debug info

Additional Information

No response

github-actions[bot] commented 1 week ago

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

vdonato commented 1 week ago

Thanks for reporting this @dwvisser. I'm currently actively working on some additional features/bugfixes/etc before we look to remove the experimental_ prefix from the fragment decorator in July's release, so I'll spend some time looking into this bug soon (will most likely start work on it next week).