mirror of https://github.com/tiangolo/fastapi.git
🐛 Fix form field regression (#12194)
This commit is contained in:
parent
0fc6e34135
commit
88d4f2cb18
|
|
@ -788,7 +788,7 @@ async def _extract_form_body(
|
|||
tg.start_soon(process_fn, sub_value.read)
|
||||
value = serialize_sequence_value(field=field, value=results)
|
||||
if value is not None:
|
||||
values[field.name] = value
|
||||
values[field.alias] = value
|
||||
for key, value in received_body.items():
|
||||
if key not in values:
|
||||
values[key] = value
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import List, Optional
|
|||
from dirty_equals import IsDict
|
||||
from fastapi import FastAPI, Form
|
||||
from fastapi.testclient import TestClient
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from typing_extensions import Annotated
|
||||
|
||||
app = FastAPI()
|
||||
|
|
@ -14,6 +14,7 @@ class FormModel(BaseModel):
|
|||
lastname: str
|
||||
age: Optional[int] = None
|
||||
tags: List[str] = ["foo", "bar"]
|
||||
alias_with: str = Field(alias="with", default="nothing")
|
||||
|
||||
|
||||
@app.post("/form/")
|
||||
|
|
@ -32,6 +33,7 @@ def test_send_all_data():
|
|||
"lastname": "Sanchez",
|
||||
"age": "70",
|
||||
"tags": ["plumbus", "citadel"],
|
||||
"with": "something",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200, response.text
|
||||
|
|
@ -40,6 +42,7 @@ def test_send_all_data():
|
|||
"lastname": "Sanchez",
|
||||
"age": 70,
|
||||
"tags": ["plumbus", "citadel"],
|
||||
"with": "something",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -51,6 +54,7 @@ def test_defaults():
|
|||
"lastname": "Sanchez",
|
||||
"age": None,
|
||||
"tags": ["foo", "bar"],
|
||||
"with": "nothing",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -100,13 +104,13 @@ def test_no_data():
|
|||
"type": "missing",
|
||||
"loc": ["body", "username"],
|
||||
"msg": "Field required",
|
||||
"input": {"tags": ["foo", "bar"]},
|
||||
"input": {"tags": ["foo", "bar"], "with": "nothing"},
|
||||
},
|
||||
{
|
||||
"type": "missing",
|
||||
"loc": ["body", "lastname"],
|
||||
"msg": "Field required",
|
||||
"input": {"tags": ["foo", "bar"]},
|
||||
"input": {"tags": ["foo", "bar"], "with": "nothing"},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue