reflex-dev / reflex

πŸ•ΈοΈ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
19.15k stars 1.08k forks source link

Upgrade to Pydantic 2.0 #1539

Open picklelo opened 1 year ago

picklelo commented 1 year ago

We should update to the latest Pydantic version to benefit from performance improvements and compatibility with other libraries that are migrating.

masenf commented 1 year ago

Blockers:

lxbxinwei commented 1 year ago

+1, Recommend!

danik292 commented 1 year ago

I can help you with this.

masenf commented 1 year ago

Sounds great! Have you worked with pydantic internals much before?

There's a branch that some contributors have started working on getting sqlmodel going with pydantic v2 that is where I started a few weeks ago: https://github.com/tiangolo/sqlmodel/pull/632

Then the next step is getting reflex Base working with pydantic v2. I don't remember the exact errors I was hitting a few weeks ago, but trying to find a public alternative to ModelField was one of the main blockers. Since all reflex Vars and State is based on pydantic, there's quite a bit to fix up.

Good luck, check in and let us know how it's going.

Getting to pydantic v2 / sqlalchemy v2 will be big for Reflex.

danik292 commented 1 year ago

Sounds great! Have you worked with pydantic internals much before?

NO i hevent.😣

benedikt-bartscher commented 9 months ago

sqlmodel 0.0.14 has been released with pydantic v2 support: https://github.com/tiangolo/sqlmodel/releases/tag/0.0.14

deanchanter commented 8 months ago

This is blocking me as most of the libraries I am using on my project have moved to Pydantic 2!

ericfeunekes commented 7 months ago

but trying to find a public alternative to ModelField was one of the main blockers.

@masenf I'm not sure how you're using ModelField internally, but does this help: https://docs.pydantic.dev/2.0/migration/#changes-to-validators-allowed-signatures

Looks like there is an approach documented for migration.

jspaezp commented 7 months ago

I would add to the issues the fact that reflex-hosting-cli also depends on pydantic <2, so anyone that wants to contribute to the migration needs to handled that as well (I don't believe I have access to that repo ... LMK if there is anything I need to do to get access and potentially help with the migration)

Poetry output when resolving deps Because reflex-hosting-cli (0.1.4) depends on pydantic (>=1.10.2,<2.0.0)

masenf commented 7 months ago

There is a WiP branch: masenf/pydantic-v2 that I started on, but has been put on hold while the team worked on the radix components.

Now that's done, work may resume on pydantic v2 upgrade... but there are quite a few non-trivial bits that were blocking before and I don't think any of them have been resolved. Moving to v2 will require architectural work, and it's not clear if reflex should take that pydantic v2 dependency or try to retool onto dataclasses/attrs and raw sqlalchemy instead.

Pydantic v1 was great for getting Reflex off the ground, but if the work required to accommodate v2 is too great, then it might make more sense to not take the dependency at all and reduce the footprint and abstraction layers needed to use Reflex.