[Question] Pydantic v2 compatibility
arthurdjn opened this issue · 4 comments
When will there be a version on pypi / conda compatible with pydantic v2 ? From the repo it looks like it is ready.
Seems like resolution is not yet complete:
INFO: pip is looking at multiple versions of geojson-pydantic to determine which version is compatible with other requirements. This could take a while.
ERROR: Cannot install geojson-pydantic==0.6.3 and pydantic==2.0 because these package versions have conflicting dependencies.
The conflict is caused by:
The user requested pydantic==2.0
geojson-pydantic 0.6.3 depends on pydantic~=1.0
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
You tried to install geojson-pydantic
from pip in an environment with pydantic
2.0.0. It won't work because the version of geojson-pydantic
that is on pypi (<=0.6.3) is only compatible with pydantic < 2.0.0.
If you install geojson-pydantic
from the git repo everything looks fine. My question is when will this package be pushed to pypi, so it will be easier to install in other environments.
It looks like the generic use of FeatureCollection
is not quite ready. When used in combination with fastapi, for example:
from geojson_pydantic import FeatureCollection
from geojson_pydantic.geometries import Geometry
from pydantic import BaseModel
from fastapi import FastAPI
class MyProperties(BaseModel):
a: int
MyFeatureCollection = FeatureCollection[Geometry, MyProperties]
app = FastAPI()
@app.get("/api/geojson", response_model=MyFeatureCollection)
def get_geojson() -> MyFeatureCollection:
return MyFeatureCollection.model_validate({"type": "FeatureCollection", "features": []})
if __name__ == "__main__":
uvicorn.run("main:app", host="localhost", port=8000, reload=True)
I get the following error:
Traceback (most recent call last):
File ".venv/lib/python3.10/site-packages/pydantic/type_adapter.py", line 149, in __init__
core_schema = _getattr_no_parents(type, '__pydantic_core_schema__')
File ".venv/lib/python3.10/site-packages/pydantic/type_adapter.py", line 94, in _getattr_no_parents
raise AttributeError(attribute)
AttributeError: __pydantic_core_schema__
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 461, in _generate_schema
obj = _typing_extra.evaluate_fwd_ref(obj, globalns=self.types_namespace)
File ".venv/lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py", line 421, in evaluate_fwd_ref
return ref._evaluate(globalns=globalns, localns=localns, recursive_guard=frozenset())
File "/usr/lib/python3.10/typing.py", line 694, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
NameError: name 'Geometry' is not defined
The error seems coming from the GeometryCollection
model from the Geometry
type.
Note that with geojson_pydantic v0.6.3 and pydantic v1.9.1 the above code runs.
versions
- geojson_pydantic latest version from the git
- pydantic version 2.0.2
My question is when will this package be pushed to pypi, so it will be easier to install in other environments.
We don't have a date yet, there are couple issues we wanted to fix first
Thanks for the FastAPI issue, might be worth opening a new issue for this