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

InputUI.render_ui silences important streamlit exceptions #29

Open
falcaopetri opened this issue May 25, 2023 · 1 comment
Open

InputUI.render_ui silences important streamlit exceptions #29

falcaopetri opened this issue May 25, 2023 · 1 comment
Labels
type:bug Something isn't working

Comments

@falcaopetri
Copy link

Describe the bug:
My specific use case was combining sp.pydantic_form and a List data field:

from typing import List

import streamlit_pydantic as sp
from pydantic import BaseModel, Field

class ShowcaseModel(BaseModel):
    int_list: List[int] = Field(..., title="Int List title", description="Int List desc")
    str_list: List[str]

session_data = sp.pydantic_form(
    key="form",
    model=ShowcaseModel
)

This yields the following:

Note: I'm filing this as a bug since the current behavior renders a hard to debug, unexpected UI.

Expected behaviour:
I expected something similar to using sp.pydantic_input:

Additional context:
streamlit does not support buttons inside forms (see feature request in streamlit/streamlit#4892).
This is the real culprit of the half-rendered output. But it has a pretty way to inform users about what happened:

import streamlit as st

with st.form(key="key"):
    st.button("label")
    submit_button = st.form_submit_button(label="submit")

Possible Fix:
Considering the example in this issue, the rendering process stops at the first st.button found:
https://github.com/LukasMasuch/streamlit-pydantic/blob/99aea848d2b8c8301cf8622fe57aaf0c59c7a176/src/streamlit_pydantic/ui_renderer.py#L986

Then streamlit raises a StreamlitAPIException, that is silenced within InputUI.render_ui:
https://github.com/LukasMasuch/streamlit-pydantic/blob/99aea848d2b8c8301cf8622fe57aaf0c59c7a176/src/streamlit_pydantic/ui_renderer.py#L175-L180

It would be helpful to do at least one of:

  • Warn users when using sp.pydantic_form+fields that use buttons
  • Re-raise StreamlitAPIException (so streamlit properly renders it)
  • Log the exception (similarly to OutputUI.render_ui)

A similar issue can happen in other scenarios that trigger the except -> pass behavior.

I can also create a PR if you point me in the right direction.

@falcaopetri falcaopetri added the type:bug Something isn't working label May 25, 2023
@falcaopetri falcaopetri changed the title InputUI.render_ui silences import streamlit exceptions InputUI.render_ui silences important streamlit exceptions May 25, 2023
@Taik
Copy link

Taik commented Jun 7, 2023

Thanks for this issue -- I also got bit by this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants