-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support Pydantic v2 #893
Comments
@srhinos thanks! we'd like to do this, but it's not a huge priority for the core team right now. I think it's a pretty heavy lift, but we would welcome a PR if you are up for it. |
Yeah, I can give it a crack and see how it goes. I’d imagine a bunch of downstream dependencies may depend on a hard pinned pydantic v1 so unsure if I wanna quarterback this for another large ML project but if I have time this weekend I’ll dig around and report back my spike! Would y'all be open to a pr with a super minor change that’ll unpin pydantic and lean on a This might let me avoid having to do a bunch of dependency upgrading before my proposed PR could merge. |
@srhinos we would be open to that! |
I support this for compatibility with Supabase-py (I personally use it for logging, feedback and to store sources for my QnA bot). |
this is really blocking because llama-cpp-python uses pydantic 2.0.1 and then chroma won't run in the same environment as llama-cpp-python, it is crippling. |
Agreed :/ the PR has been open for a bit and I'm not knowledgeable on how chroma is using FastAPI internally to make the necessary changes to fix the issues I ran into. This will need a maintainer's eyes to either advise me on how to fix the test errors or some added commits on my open PR. |
Hi folks, thanks for the patience here. I agree this is important to unblock. I had some cycles to spend on this today. Here are my thoughts. Pydantic v2 introduced breaking, non backwards compatible changes to their API in 2.0. FastAPI adopted these changes in >=0.100. Many of our users would like to be able to use a fastapi >= 0.100 AND/OR pydantic >= 2.0. We don't really need any of the performance or functionality changes that come with each release, but we'd like to be able to support these users. Projects like llama python use pydantic >= 2.0. Pydantics way to support backwards compatibility, is to bundle a "pydantic.v1" namespace which holds the old version. One would expect a naive solution to this to be to upgrade to pydantic 2, switch our imports to pydantic.v1 (with error fallbacks) and be off to the races. Alas, this is not the case. FastAPI claimed to be able to support pydantic v1 AND v2 in >= 0.100, but it is not capable of doing so at runtime (fastapi/fastapi#9966). It statically determines if you are in V1 mode or V2 mode based solely on the package that is installed. So imports from pydantic.v1 will not work out of the box. This leaves options, which fundamentally trade complexity on our side, for potential inconvenience to various user cohorts.
There are perhaps a couple other options but these ones are the main ones I see. I do not think it is possible to support the 2x2 of fastapi below 0.100.0 and above, as well as pydantic above v2 and below in a reasonable way. |
@samuelcolvin @srhinos If you have any thoughts it would be appreciated! |
@HammadB honestly I think there's a kinda hacky method that'll address this while still allowing v1 and v2 support on pre and post 0.100.0. I felt that moving the pydantic models that are causing issues into a separate file ie Maybe this strategy might work? I'm not really too sure the extent of this bug within fastapi preventing v1 models within >0.100.0 but it'd at least let us maintain backwards compatibility. |
That's worth a shot. I don't love the maintainability but we rarely mutate the API surface so that might be OK. Maximizing the compatibility of chroma is important. Thanks for the idea. Let me try that. |
Ok found a much simpler solution. That covers 3/4 cases. I'm not super worried about supporting #1.
Only needed change was how we import BaseSettings and changing how the Collection.py model initializes, and some test fixes. |
Nice! Wanna add the changes to my open PR and we can get it merged in? |
The changes are in #1174 referenced above. Should get released Monday |
## Description of changes Closes #893 *Summarize the changes made by this PR.* - Improvements & Bug fixes - Adds support for pydantic v2.0 by changing how Collection model inits - this simple change fixes pydantic v2 - Fixes the cross version tests to handle pydantic specifically - Conditionally imports pydantic-settings based on what is available. In v2 BaseSettings was moved to a new package. - New functionality - N/A ## Test plan Existing tests were run with the following configs 1. Fastapi < 0.100, Pydantic >= 2.0 - Unsupported as the fastapi dependencies will not allow it. They likely should, as pydantic.v1 imports would support this, but this is a downstream issue. 2. Fastapi >= 0.100, Pydantic >= 2.0, Supported via normal imports ✅ (Tested with fastapi==0.103.1, pydantic==2.3.0) 3. Fastapi < 0.100 Pydantic < 2.0, Supported via normal imports ✅ (Tested with fastapi==0.95.2, pydantic==1.9.2) 4. Fastapi >= 0.100, Pydantic < 2.0, Supported via normal imports ✅ (Tested with latest fastapi, pydantic==1.9.2) - [x] Tests pass locally with `pytest` for python, `yarn test` for js ## Documentation Changes None required.
This should be fixed now in 0.4.13 |
Pydantic has gone live with their new version
Being that its production ready and as suggested by Pydantic's README:
It should be safe to upgrade and allow folks using poetry (like me) to resolve dependancies in a way that unblocks upgrading to Pydantic v2, FastAPI v0.100.0, etc
The text was updated successfully, but these errors were encountered: