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
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:

self._render_list_add_button(key, add_col, data_list)

Then streamlit raises a StreamlitAPIException, that is silenced within InputUI.render_ui:

try:
value = self._render_property(streamlit_app, property_key, property)
if not self._is_value_ignored(property_key, value):
self._store_value(property_key, value)
except Exception:
pass

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 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
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants