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

Update Pydantic patch for Lite that emulates PydanticV2 API using V1 #7365

Merged
merged 6 commits into from Feb 9, 2024

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Feb 9, 2024

Description

The following error started to occur on Lite after #7333.
Because Pydantic V2 is not available on Pyodide yet, Lite still uses Pydantic V1 with patches bridging the V1 APIs to V2 interfaces so the original Gradio code relying on the V2 API works.
The patch didn't support the Config class API V1, which is deprecated in V2 and #7333 switched from to the new one. This PR updates the patch to support the configuration interface in V2 using the V1 API.

Error
Traceback (most recent call last): File "/lib/python311.zip/_pyodide/_base.py", line 571, in eval_code_async await CodeRunner( File "/lib/python311.zip/_pyodide/_base.py", line 394, in run_async coroutine = eval(self.code, globals, locals) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<exec>", line 1, in <module> File "/lib/python3.11/site-packages/gradio/__init__.py", line 3, in <module> import gradio._simple_templates File "/lib/python3.11/site-packages/gradio/_simple_templates/__init__.py", line 1, in <module> from .simpledropdown import SimpleDropdown File "/lib/python3.11/site-packages/gradio/_simple_templates/simpledropdown.py", line 6, in <module> from gradio.components.base import FormComponent File "/lib/python3.11/site-packages/gradio/components/__init__.py", line 1, in <module> from gradio.components.annotated_image import AnnotatedImage File "/lib/python3.11/site-packages/gradio/components/annotated_image.py", line 11, in <module> from gradio import processing_utils, utils File "/lib/python3.11/site-packages/gradio/processing_utils.py", line 22, in <module> from gradio.data_classes import FileData, GradioModel, GradioRootModel File "/lib/python3.11/site-packages/gradio/data_classes.py", line 65, in <module> class PredictBody(BaseModel): File "/lib/python3.11/site-packages/pydantic/main.py", line 197, in __new__ fields[ann_name] = ModelField.infer( ^^^^^^^^^^^^^^^^^ File "/lib/python3.11/site-packages/pydantic/fields.py", line 506, in infer return cls( ^^^^ File "/lib/python3.11/site-packages/pydantic/fields.py", line 436, in __init__ self.prepare() File "/lib/python3.11/site-packages/pydantic/fields.py", line 557, in prepare self.populate_validators() File "/lib/python3.11/site-packages/pydantic/fields.py", line 831, in populate_validators *(get_validators() if get_validators else list(find_validators(self.type_, self.model_config))), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/lib/python3.11/site-packages/pydantic/validators.py", line 765, in find_validators raise RuntimeError(f'no validator found for {type_}, see `arbitrary_types_allowed` in Config') RuntimeError: no validator found for <class 'starlette.requests.Request'>, see `arbitrary_types_allowed` in Config

PythonError: Traceback (most recent call last):
  File "/lib/python311.zip/_pyodide/_base.py", line 571, in eval_code_async
    await CodeRunner(
  File "/lib/python311.zip/_pyodide/_base.py", line 394, in run_async
    coroutine = eval(self.code, globals, locals)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<exec>", line 1, in <module>
  File "/lib/python3.11/site-packages/gradio/__init__.py", line 3, in <module>
    import gradio._simple_templates
  File "/lib/python3.11/site-packages/gradio/_simple_templates/__init__.py", line 1, in <module>
    from .simpledropdown import SimpleDropdown
  File "/lib/python3.11/site-packages/gradio/_simple_templates/simpledropdown.py", line 6, in <module>
    from gradio.components.base import FormComponent
  File "/lib/python3.11/site-packages/gradio/components/__init__.py", line 1, in <module>
    from gradio.components.annotated_image import AnnotatedImage
  File "/lib/python3.11/site-packages/gradio/components/annotated_image.py", line 11, in <module>
    from gradio import processing_utils, utils
  File "/lib/python3.11/site-packages/gradio/processing_utils.py", line 22, in <module>
    from gradio.data_classes import FileData, GradioModel, GradioRootModel
  File "/lib/python3.11/site-packages/gradio/data_classes.py", line 65, in <module>
    class PredictBody(BaseModel):
  File "/lib/python3.11/site-packages/pydantic/main.py", line 197, in __new__
    fields[ann_name] = ModelField.infer(
                       ^^^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/pydantic/fields.py", line 506, in infer
    return cls(
           ^^^^
  File "/lib/python3.11/site-packages/pydantic/fields.py", line 436, in __init__
    self.prepare()
  File "/lib/python3.11/site-packages/pydantic/fields.py", line 557, in prepare
    self.populate_validators()
  File "/lib/python3.11/site-packages/pydantic/fields.py", line 831, in populate_validators
    *(get_validators() if get_validators else list(find_validators(self.type_, self.model_config))),
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/pydantic/validators.py", line 765, in find_validators
    raise RuntimeError(f'no validator found for {type_}, see `arbitrary_types_allowed` in Config')
RuntimeError: no validator found for <class 'starlette.requests.Request'>, see `arbitrary_types_allowed` in Config

    at new_error (https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.js:9:12519)
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[295]:0x158827
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[452]:0x15fcd5
    at _PyCFunctionWithKeywords_TrampolineCall (https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.js:9:123040)
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[1057]:0x1a3091
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[3387]:0x289e4d
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[2037]:0x1e3f77
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[1064]:0x1a3579
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[1067]:0x1a383a
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[1068]:0x1a38dc
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[3200]:0x2685c5
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[3201]:0x26e3d0
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[1070]:0x1a3a04
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[1065]:0x1a3694
    at https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.wasm:wasm-function[440]:0x15f45e
    at Module.callPyObjectKwargs (https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.js:9:81732)
    at Module.callPyObject (https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.js:9:82066)
    at wrapper (https://cdn.jsdelivr.net/pyodide/v0.24.0/full/pyodide.asm.js:9:58562)

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 9, 2024

🪼 branch checks and previews

Name Status URL
Spaces building...
Website ready! Website preview
🦄 Changes detected! Details

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 9, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Update Pydantic patch for Lite that emulates PydanticV2 API using V1

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@whitphx whitphx marked this pull request as ready for review February 9, 2024 08:52
gradio/data_classes.py Outdated Show resolved Hide resolved
@whitphx whitphx added the gradio-lite Related to the @gradio/lite library label Feb 9, 2024
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice @whitphx !!

@whitphx whitphx merged commit 1e68561 into main Feb 9, 2024
9 checks passed
@whitphx whitphx deleted the fix-pydantic-patch-lite branch February 9, 2024 14:43
@pngwn pngwn mentioned this pull request Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gradio-lite Related to the @gradio/lite library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants