streamlit-pydantic
streamlit-pydantic copied to clipboard
Update functionality to support pydantic 2.0+
What kind of change does this PR introduce?
- [x] Bugfix
- [ ] New Feature
- [x] Feature Improvement
- [ ] Refactoring
- [x] Documentation
- [ ] Other, please describe:
Description:
Since the breaking changes introduced upstream in Pydantic 2.0+, many of the features in this library have not been working correctly.
This PR updates the library and its showcase apps to support the latest Pydantic version (2.7).
This should fix multiple reported issues with the showcase apps and any downstream apps that use anything but very basic functionality.
Fort reference this PR has been tested with:
Pydantic: 2.7
Python: 3.11
Streamlit: 1.33.0
Earlier versions of these might work but are untested.
Change Summary: The majority of the changes are self explanatory. Many pydantic functions and structures that this library relied on have changed or have been deprecated upstream.
There are some more significant changes though that should be noted before merging:
- The custom
FileContent
type has been removed in favour of the pydantics 2.0+ built inBase64UrlBytes
. The resulting emptytypes.py
and its documentation have been removed (maybe this is bad idea). (seeexamples/complex_showcase.py
) - The handling of
DataClasses
has changed significantly in pydantic 2.0+ and this required more rework on the lib side. As a result though the return ofDataClass
instances fromsp.pydantic_form()
is now properly supported (seeexamples/dataclass_form.py
) -
sp.pydantic_output()
has been improved slightly to support more complex pydantic models but could still use more work. - Pydantic 2.0+handling of
Fields
tagged asOptional
is significantly different (as mentioned in #50) and currently not supported within the library. Examples have been updated to remove theOptional
tag.
Checklist:
- [x] I have read the CONTRIBUTING document.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
Closes #55, #56, #53, #38
@HIL340 thanks for the contribution! 👍 I will take a closer look later this week
Any updates?
Used this as a way to test using the branch specific implementation.
pip uninstall streamlit_pydantic pydantic-settings poetry remove streamlit_pydantic
pip install git+https://github.com/HIL340/[email protected] poetry add streamlit-pydantic@git+https://github.com/HIL340/streamlit-pydantic.git#pydantic-2.7
Is there an update on this? @LukasMasuch, where can we support you?
Used this as a way to test using the branch specific implementation.
pip uninstall streamlit_pydantic pydantic-settings poetry remove streamlit_pydantic
pip install git+https://github.com/HIL340/[email protected] poetry add streamlit-pydantic@git+https://github.com/HIL340/streamlit-pydantic.git#pydantic-2.7
very useful, thanks
@HIL340 I think the github actions versions need to be updated too. The action/checkout
current version is v4, not v2.
https://github.com/actions/checkout/releases/tag/v4.1.7
@gaby I updated the action/checkout
to v4 but it did not resolve the build issue.
looks like we will need to refactor CICD to reproduce easier
https://github.com/ml-tooling/universal-build releaser is out of date
nowadays is easier to release packages
https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
@pablodz Agree the whole ci has to be refactored
This PR is arguably already a bit large and my experience with GitHub actions is fairly limited.
If the CI needs significant rework anyway and as long as this PR is not making the situation worse I'd suggest merging this one in and tackling the CI issues in a separate PR.
@HIL340 , I agree. I also tested this change locally and can confirm it works. There are still a ton of issues we need to solve, but this is definitely a step forward. @LukasMasuch , should I merge this? (and, as a general question, do you want me to freely make changes and merge PRs, or do you want to be the one to approve all PRs before they're merged?)
@MatanRubin
and, as a general question, do you want me to freely make changes and merge PRs, or do you want to be the one to approve all PRs before they're merged?
I configured it so that changes to main
will require a PR that is approved by at least one other person (it does not have to be me). I'm happy also to add more maintainers if anyone is interested :)