Skip to content
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

Using pydantic>2 requires specifying fastapi version, too #2112

Open
nickstenning opened this issue Jan 17, 2025 · 1 comment
Open

Using pydantic>2 requires specifying fastapi version, too #2112

nickstenning opened this issue Jan 17, 2025 · 1 comment
Assignees

Comments

@nickstenning
Copy link
Member

nickstenning commented Jan 17, 2025

I encountered today the surprising fact that the following cog.yaml results in a broken image:

build:
  gpu: false
  python_version: "3.12"
  python_packages:
    - "pydantic>2"
predict: "predict.py:Predictor"

The build fails with the following error:

[...]
#14 DONE 0.7s
Validating model schema...

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/lib/python3.12/site-packages/cog/command/openapi_schema.py", line 13, in <module>
    from ..server.http import create_app
  File "/usr/local/lib/python3.12/site-packages/cog/server/http.py", line 18, in <module>
    from fastapi import Body, FastAPI, Header, Path, Response
  File "/usr/local/lib/python3.12/site-packages/fastapi/__init__.py", line 7, in <module>
    from .applications import FastAPI as FastAPI
  File "/usr/local/lib/python3.12/site-packages/fastapi/applications.py", line 16, in <module>
    from fastapi import routing
  File "/usr/local/lib/python3.12/site-packages/fastapi/routing.py", line 22, in <module>
    from fastapi import params
  File "/usr/local/lib/python3.12/site-packages/fastapi/params.py", line 4, in <module>
    from pydantic.fields import FieldInfo, Undefined
ImportError: cannot import name 'Undefined' from 'pydantic.fields' (/usr/local/lib/python3.12/site-packages/pydantic/fields.py)

ⅹ Failed to get type signature: exit status 1

As far as I can tell the problem here is that fastapi==0.98 is installed by default in the cog-base images, but this is actually not compatible with Pydantic v2.

It's possible to make a working image by specifying a tighter range of acceptable versions for fastapi, but I don't think this is ideal for users:

build:
  gpu: false
  python_version: "3.12"
  python_packages:
    - "fastapi>0.100.0,<0.111.0"
    - "pydantic>2"
predict: "predict.py:Predictor"
@8W9aG
Copy link
Contributor

8W9aG commented Jan 17, 2025

#2115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants