Incompatibility with pydantic version 2
teddygroves opened this issue ยท 6 comments
Problem description
I would like my project to have both the latest versions of cobrapy and pydantic as dependencies.
However this isn't currently possible as cobrapy pins pydantic version 1.6.
This is a problem because pydantic version 2 introduced some breaking changes, so would take a lot of work to make my project compatible with version 1.6.
Code Sample
Here is a minimal pyproject.toml
that demonstrates the problem
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "myproject"
version = "0.0.1"
dependencies = [
"cobra >= 0.26.3",
"pydantic >= 2.0.0",
]
and here is the error message when I run pip install -e .
in an empty folder containing this pyproject.toml
:
ERROR: Cannot install cobra==0.26.3 and myproject==0.0.1 because these package versions have conflicting dependencies.
The conflict is caused by:
myproject 0.0.1 depends on pydantic>=2.0.0
cobra 0.26.3 depends on pydantic~=1.6
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
From a quick look I don't think cobrapy uses pydantic except for in this file, which I think is compatible with pydantic version 2 as is. It therefore doesn't seem like a very hard bug to fix: just remove the pin or change it to a version greater than 2.
Context
Not relevant as the bug happens before cobra is installed
Seems reasonable to me. Feel free to send a PR with a newer requirement. That way we will see if the CI passes.
Maybe just >=1.6 would allow both users of <2 and >2 to happily use cobrapy.
The PR above just changes the ~
here to a >
as @Midnighter suggests.
I think the CI is just waiting for a maintainer to approve before it sets off.
Now fixed in 0.27.0.