-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Working with Pydantic v1 while having v2 installed #10360
Comments
In case it helps, I started PR about that: |
This comment was marked as spam.
This comment was marked as spam.
It seems people have been primarily doing that on #10223 and in issues opened against a heap of other projects (see above). It also means that FastAPI doesn't really support pydantic v1 as indicated here. Specifically, it doesn't really support pydantic v2, since the backwards compatibility with pydantic v1 models is an important feature of that version allowing progressive upgrades. Unfortunately that PR, though well-intentioned, appears to be abandoned. It's a bit lacking in detail as to what's left to be done or why it's not ready to merge, so it seems unlikely anyone'll be able to pick it up either - which given the amount of people asking about its status might otherwise have happened, though I'm under no illusion that it's much easier to ask about progress than to act on it yourself 😄 |
@tiangolo Any update on this issue?? |
Any way of getting some visibility here? It’s currently very hard to migrate for large code bases. |
Joining the thread as well, I'm WIP updating from Pydantic V1 to V2 on a massive code base with dozens of FastAPI routes and hundreds of models. I use the "from pydantic.v1 import BaseModel" approach, however I have failures to generate OpenApi schema using FastAPI "get_openapi" utility since the schema generation fails when encountering a field with Pydantic V1 |
A good compromise might be if the pydantic v1 vs v2 logic was applied per Devs with a large code base can then migrate per router (and, if need be, break up their app to use multiple routers). This assumes that implementing this at the |
Discussed in #9966
Originally posted by slafs July 29, 2023
This is a continuation of a topic introduced in #9709 (comment) as requested by @Kludex. I've chosen the "Show and tell" category as the (lack of) template seems better for this discussion.
In the original thread I've asked if there's a way to work with pydantic v1 while having v2 installed:
Pydantic v2 ships the latest version of v1 for easier migration, so the pattern is to work with v1 via things like
from pydantic.v1 import BaseModel
etc. while having v2 installed.Currently, this approach doesn't seem to work with FastAPI 0.100.0 and the following snippet:
produces the following error:
Switching from
pydantic.v1
to justpydantic
(v2) obviously works.I'm seeing there's
fastapi._compat
module andPYDANTIC_V2
var, but I'm not sure if that's the right direction.For reference, installed versions:
Now... that being said, I'm not even sure if this would be helpful to anyone even if FastAPI did support it. My initial thought was that this would ease the migration, but the reality seems more complicated. E.g. models are used by other models and even Pydantic itself doesn't support mixing v1 and v2 together. So given that the cost of figuring out the plan for the gradual migration seems comparable with doing the whole migration at once (at least for us).
Maybe it would be useful if people commented on their intended use case and see if that's actually a feature that's needed/wanted.
The text was updated successfully, but these errors were encountered: