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

Crash on launch with Pydantic 2.11b1 #10792

Open
1 task done
maxfriedrich opened this issue Mar 12, 2025 · 2 comments · May be fixed by #10798
Open
1 task done

Crash on launch with Pydantic 2.11b1 #10792

maxfriedrich opened this issue Mar 12, 2025 · 2 comments · May be fixed by #10798
Labels
bug Something isn't working

Comments

@maxfriedrich
Copy link

Describe the bug

I tried my Gradio app with the Pydantic 2.11 beta and it crashes on launch. Pydantic 2.11 will be released this month: pydantic/pydantic#11194

It looks to me like this change may have broken the schema parsing in gradio-client: pydantic/pydantic#11392

Schemas now look like this:

{
  'description': 'The FileData class is a subclass of the GradioModel class that represents a file object within a Gradio interface. It is used to store file data and metadata when a file is uploaded.\n\nAttributes:\n    path: The server file path where the file is stored.\n    url: The normalized server URL pointing to the file.\n    size: The size of the file in bytes.\n    orig_name: The original filename before upload.\n    mime_type: The MIME type of the file.\n    is_stream: Indicates whether the file is a stream.\n    meta: Additional metadata used internally (should not be changed).',
  'properties': {
    'path': {'title': 'Path', 'type': 'string'},
    'url': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'default': None, 'title': 'Url'},
    'size': {'anyOf': [{'type': 'integer'}, {'type': 'null'}], 'default': None, 'title': 'Size'},
    'orig_name': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'default': None, 'title': 'Orig Name'},
    'mime_type': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'default': None, 'title': 'Mime Type'},
    'is_stream': {'default': False, 'title': 'Is Stream', 'type': 'boolean'},
    'meta': {
      # problem seems to be here:
      'additionalProperties': True,
      'default': {'_type': 'gradio.FileData'}, 'title': 'Meta', 'type': 'object'}
  }, 
  'required': ['path'],
  'title': 'FileData', 'type': 'object'}
}

This means _json_schema_to_python_type(True, ...) is called here, which crashes:

if "additionalProperties" in schema:
des += [
f"str, {_json_schema_to_python_type(schema['additionalProperties'], defs)}"
]

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

e.g. the "upload_button" example with Pydantic 2.11b1 installed:

import gradio as gr

def upload_file(files):
    file_paths = [file.name for file in files]
    return file_paths

with gr.Blocks() as demo:
    file_output = gr.File()
    upload_button = gr.UploadButton("Click to Upload a File", file_types=["image", "video"], file_count="multiple")
    upload_button.upload(upload_file, upload_button, file_output)

demo.launch()

Screenshot

No response

Logs

❯ uv run pydantic_211.py
* Running on local URL:  http://127.0.0.1:7861
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self.scope, self.receive, self.send
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio/route_utils.py", line 789, in __call__
    await self.app(scope, receive, send)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/routing.py", line 714, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/routing.py", line 734, in app
    await route.handle(scope, receive, send)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
               ^^^^^^^^^^^^^^^^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/fastapi/routing.py", line 301, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/fastapi/routing.py", line 214, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/starlette/concurrency.py", line 37, in run_in_threadpool
    return await anyio.to_thread.run_sync(func)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        func, args, abandon_on_cancel=abandon_on_cancel, limiter=limiter
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2461, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 962, in run
    result = context.run(func, *args)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio/routes.py", line 584, in main
    gradio_api_info = api_info(request)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio/routes.py", line 615, in api_info
    api_info = utils.safe_deepcopy(app.get_blocks().get_api_info())
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio/blocks.py", line 3015, in get_api_info
    python_type = client_utils.json_schema_to_python_type(info)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio_client/utils.py", line 931, in json_schema_to_python_type
    type_ = _json_schema_to_python_type(schema, schema.get("$defs"))
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio_client/utils.py", line 976, in _json_schema_to_python_type
    elements = _json_schema_to_python_type(items, defs)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio_client/utils.py", line 946, in _json_schema_to_python_type
    return _json_schema_to_python_type(defs[schema["$ref"].split("/")[-1]], defs)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio_client/utils.py", line 986, in _json_schema_to_python_type
    f"{n}: {_json_schema_to_python_type(v, defs)}{get_desc(v)}"
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio_client/utils.py", line 993, in _json_schema_to_python_type
    f"str, {_json_schema_to_python_type(schema['additionalProperties'], defs)}"
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio_client/utils.py", line 939, in _json_schema_to_python_type
    type_ = get_type(schema)
  File "/Users/max.friedrich/gradio-pydantic-211-repro/.venv/lib/python3.13/site-packages/gradio_client/utils.py", line 898, in get_type
    if "const" in schema:
       ^^^^^^^^^^^^^^^^^
TypeError: argument of type 'bool' is not iterable

System Info

Gradio Environment Information:
------------------------------
Operating System: Darwin
gradio version: 5.20.1
gradio_client version: 1.7.2

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
anyio: 4.8.0
audioop-lts: 0.2.1
fastapi: 0.115.11
ffmpy: 0.5.0
gradio-client==1.7.2 is not installed.
groovy: 0.1.2
httpx: 0.28.1
huggingface-hub: 0.29.3
jinja2: 3.1.6
markupsafe: 2.1.5
numpy: 2.2.3
orjson: 3.10.15
packaging: 24.2
pandas: 2.2.3
pillow: 11.1.0
pydantic: 2.11.0b1
pydub: 0.25.1
python-multipart: 0.0.20
pyyaml: 6.0.2
ruff: 0.9.10
safehttpx: 0.1.6
semantic-version: 2.10.0
starlette: 0.46.1
tomlkit: 0.13.2
typer: 0.15.2
typing-extensions: 4.12.2
urllib3: 2.3.0
uvicorn: 0.34.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2025.3.0
httpx: 0.28.1
huggingface-hub: 0.29.3
packaging: 24.2
typing-extensions: 4.12.2
websockets: 15.0.1

Severity

I can work around it

@maxfriedrich maxfriedrich added the bug Something isn't working label Mar 12, 2025
@freddyaboulton
Copy link
Collaborator

Do you want to open a PR @maxfriedrich ?

@maxfriedrich
Copy link
Author

@freddyaboulton Sure, I'll give it a shot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants