In my Python FastAPI app, I need Pydantic version 2 to solve an issue with Unions
that is fixed in version 2 only.
Since FastAPI version 0.100.0 and onward supports Pydantic v2, I was first hopeful that depending on Pydantic v2 would work fine, however another indirect depdendency in my project called sqlmodel specifies to only support Pedantic 1.x.
sqlmodel is incidently also written by tiangolo which is the author of FastAPI and he stated that sqlmodel would get a version bump with support for Pydantic v2, the discussion can be seen here. But this has taken some time and has caused a lot of problems for many users and prompted someone to create a fork of sqlmodel, patching it to support Pydantic v2.
I want to use this forked version of sqlmodel in my project to get Pydantic v2 support installed without the dependency problems. I know it is possible to specify a git repo directly in my requirements.txt
file using the -e git+https://github.com/author/project.git@branch_tag_or_hash#egg=packagename
syntax, however when I try this with the fork of sqlmodel I get an error because now sqlmodel has version "0" according to pip.
The exact syntax I have used in my requirements.txt looks like this:
-e git+https://github.com/honglei/sqlmodel.git@main#egg=sqlmodel
and the exact error message after running pip install -r requirements.txt looks like this:
ERROR: Cannot install sqlmodel 0 (from git+https://github.com/honglei/sqlmodel.git@main#egg=sqlmodel) because these package versions have conflicting dependencies.
As you can clearly see, pip thinks we are installing "version 0" of sqlmodel now which is clearly not the case.
So there are two questions;
How can I convince pip that the git fork of sqlmodel is actually version 0.0.9 or some other arbitrary value that makes it be accepted as the latest version of the package during dependency resolution?
Taking a step back, are there any more elegant ways to resolve this? It seems quite radical and hacky to depend on a fork in github, but I don't see any other way of having FastAPI and Pydantic v2 in my app at this point.
pipdeptree
to view the dependency tree and see which package depends on it. – Jumpy