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

Forms for list-valued models do not work #39

Open
szabi opened this issue Jul 25, 2023 · 2 comments
Open

Forms for list-valued models do not work #39

szabi opened this issue Jul 25, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@szabi
Copy link
Contributor

szabi commented Jul 25, 2023

This bug regarding lists-values was first described in a comment to #36. #36 in the strict sense is fixed by merged-not-yet-released PR #37. I open this issue to track the list-valued problem separately, which does not seem to be related to pydantic 2.

Describe the bug:

List valued models do not work. There is code in streamlit-pydantic for handling list-valued models that suggest that it might have worked earlier, but at least with current versions of streamlit, list-valued models do not render as forms.

List-Editing is solved in streamlit-pydantic among others by adding a button: self._render_list_add_button(key, add_col, data_list) (ui_renderer.py:1000), but that tries to add a streamlit.button(...) to the interface. However, adding a regular button within a form is disallowed by streamlit button.py:407-411 raising an exception. Only form-submit buttons are currently allowed in Streamlit within forms. (The exception raising was part of Streamlit from the very beginning of adding the "form" feature in April 2021, so it's not clear how list valued editing was supposed to work in streamlit-pydantic to begin with)

The exception then seems to be silently caught and ignored by streamlit-pydantic, so that the form does not render, correctly, but also no exception is displayed within the streamlit app.

Expected behaviour:

List valued models should be also rendered and editing should be possible with streamlit-pydantic.

Steps to reproduce the issue:

You can use the example used in #36 on a codebase which has #37 merged to reproduce. OtherSettings has : list[NonNegativeInt] values.

Technical details:

  • Host Machine OS (Windows/Linux/Mac): Windows
  • Browser (Chrome/Firefox/Safari): Firefox

Notes:

Given that the raising of the specific exception in Streamlit is quite intentional and seems to be a core design decision, an alternative mode to edit lists has to be found, if possible at all.

After a quick browse through streamlit elements it can maybe solved by a "data editor" element, though the result would likely be unsightly and cumbersome. Similarly cumbersome would be using a "text input" with some convention for splitting the values. Neither seems to be a particularly good solution, the solution space needs to be explored further.

@szabi szabi added the bug Something isn't working label Jul 25, 2023
@aantn
Copy link

aantn commented Nov 6, 2023

Also running into this issue.

I'm not very familiar with streamlit - so excuse the ignore - but what is gained by using a form other than the visual aspects? I understand that inputs are batched, but looking at the implementation for pydantic_form I'm not entirely sure the batching matters?

@jlinnett-montai
Copy link

Would love to see this fixed! This bug is the main thing keeping me from using streamlit-pydantic (and Streamlit altogether) for my auto-generated UIs. Looks super cool otherwise

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

3 participants