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

list[File] not handled correctly when one file is provided #93

Open
robocattyball opened this issue Nov 11, 2024 · 1 comment
Open

list[File] not handled correctly when one file is provided #93

robocattyball opened this issue Nov 11, 2024 · 1 comment

Comments

@robocattyball
Copy link

Validation fails when one file is provided in file.

from pydantic import BaseModel
from quart import Quart
from quart_schema import QuartSchema
from quart_schema.pydantic import File

app = Quart(__name__)
app.config["MAX_CONTENT_LENGTH"] = 150 * 1024 * 1024  # 150MB limit for rag file upload
QuartSchema(app)

class SomeOtherArguments(BaseModel):
    name: str

class Upload(SomeOtherArguments):
    file: list[File]  # Work around: `list[File] | File`

@rag_blueprint.post("/upload")
@validate_request(Upload, source=DataSource.FORM_MULTIPART)
async def rag_create(data: Upload):
    return {}, 200

Error:

{
  "errors": "74956 validation errors for Upload\nfile.0\n  Value error, Expected FileStorage, received: <class 'bytes'> ...
}

When the work around list[File] | File is used, the docs no longer handled the filed as a file, but just as a string:
Screenshot from 2024-11-11 16-02-40

@robocattyball
Copy link
Author

Version:

Quart = "0.19.8"
"quart-schema[pydantic]" = "==0.20.0"
pydantic = "2.5.3"

@robocattyball robocattyball changed the title list[File] not handled correctly when there is exactly one file is provided list[File] not handled correctly when one file is provided Nov 11, 2024
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

1 participant