-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Open
Labels
questionQuestion or problemQuestion or problem
Description
Discussed in #12227
Originally posted by MartinAchtnerAA September 19, 2024
First Check
- I added a very descriptive title here.
- I used the GitHub search to find a similar question and didn't find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google "How to X in FastAPI" and didn't find any information.
- I already read and followed all the tutorial in the docs and didn't find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from typing import Annotated, Literal, Optional
from fastapi import FastAPI, Form
from fastapi.testclient import TestClient
app = FastAPI()
@app.post("/")
async def read_main(
attribute : Annotated[Optional[Literal["abc", "def"]], Form()]
):
print(attribute)
client = TestClient(app)
data = {}
data["attribute"] = None
response = client.post("/", data=data)
print(response.content)
assert response.status_code == 200
Description
In FastAPI 0.113 .0 the above code passes.
Since version 0.114.0 the response is a 422 status code with error message '{"detail":[{"type":"literal_error","loc":["body","attribute"],"msg":"Input should be 'abc' or 'def'","input":"","ctx":{"expected":"'abc' or 'def'"}}]}'
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.114.0
Pydantic Version
2.9.1
Python Version
3.12.3
Additional Context
No response
spladug, binbjz and agbares
Metadata
Metadata
Assignees
Labels
questionQuestion or problemQuestion or problem