Skip to content

mtblanton/fastapi-form-list-repro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Form Request issue repro

This repo reproduces an issue in FastAPI where having a union as the type for a Form parameter can cause validation to be incorrect if there's only a single entry in the list.

Running

Run uv sync then run fastapi dev main.py

Example requests

  • Fails validation with single entry in list
curl --request POST \
  --url http://localhost:8000/test-union \
  --header 'content-type: multipart/form-data' \
  --form type=list \
  --form list=foo
{
  "detail": [
    {
      "type": "list_type",
      "loc": [
        "body",
        "list",
        "list"
      ],
      "msg": "Input should be a valid list",
      "input": "foo"
    }
  ]
}
  • Passes validation with multiple entries in list
curl --request POST \
  --url http://localhost:8000/test-union \
  --header 'content-type: multipart/form-data' \
  --form type=list \
  --form list=foo \
  --form list=foo2
{
  "type": "list",
  "list": [
    "foo",
    "foo2"
  ]
}
  • Passes validation when hitting an endpoint that doesn't use a union
curl --request POST \
  --url http://localhost:8000/test-no-union \
  --header 'content-type: multipart/form-data' \
  --form type=list \
  --form list=foo
{
  "type": "list",
  "list": [
    "foo"
  ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages