Skip to content

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

@robocattyball

Description

@robocattyball

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions