streamlit-pydantic icon indicating copy to clipboard operation
streamlit-pydantic copied to clipboard

Update functionality to support pydantic 2.0+

Open HIL340 opened this issue 10 months ago • 6 comments

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:

  1. The custom FileContent type has been removed in favour of the pydantics 2.0+ built in Base64UrlBytes. The resulting empty types.py and its documentation have been removed (maybe this is bad idea). (see examples/complex_showcase.py)
  2. 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 of DataClass instances from sp.pydantic_form() is now properly supported (see examples/dataclass_form.py)
  3. sp.pydantic_output() has been improved slightly to support more complex pydantic models but could still use more work.
  4. Pydantic 2.0+handling of Fields tagged as Optional is significantly different (as mentioned in #50) and currently not supported within the library. Examples have been updated to remove the Optional 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.

HIL340 avatar Apr 22 '24 15:04 HIL340

Closes #55, #56, #53, #38

HIL340 avatar Apr 22 '24 15:04 HIL340

@HIL340 thanks for the contribution! 👍 I will take a closer look later this week

lukasmasuch avatar Apr 24 '24 21:04 lukasmasuch

Any updates?

0xDeadcell avatar May 01 '24 04:05 0xDeadcell

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

alex-mlabs avatar May 02 '24 00:05 alex-mlabs

Is there an update on this? @LukasMasuch, where can we support you?

thinkORo avatar Jun 04 '24 05:06 thinkORo

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

pablodz avatar Jun 12 '24 00:06 pablodz

@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 avatar Jul 30 '24 15:07 gaby

@gaby I updated the action/checkout to v4 but it did not resolve the build issue.

HIL340 avatar Aug 05 '24 03:08 HIL340

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 avatar Aug 05 '24 20:08 pablodz

@pablodz Agree the whole ci has to be refactored

gaby avatar Aug 06 '24 03:08 gaby

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 avatar Aug 06 '24 06:08 HIL340

@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 avatar Aug 06 '24 11:08 MatanRubin

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

lukasmasuch avatar Aug 12 '24 12:08 lukasmasuch