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)
|
tg.start_soon(process_fn, sub_value.read)
|
||||||
value = serialize_sequence_value(field=field, value=results)
|
value = serialize_sequence_value(field=field, value=results)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
values[field.name] = value
|
values[field.alias] = value
|
||||||
for key, value in received_body.items():
|
for key, value in received_body.items():
|
||||||
if key not in values:
|
if key not in values:
|
||||||
values[key] = value
|
values[key] = value
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from typing import List, Optional
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi import FastAPI, Form
|
from fastapi import FastAPI, Form
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, Field
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
@ -14,6 +14,7 @@ class FormModel(BaseModel):
|
||||||
lastname: str
|
lastname: str
|
||||||
age: Optional[int] = None
|
age: Optional[int] = None
|
||||||
tags: List[str] = ["foo", "bar"]
|
tags: List[str] = ["foo", "bar"]
|
||||||
|
alias_with: str = Field(alias="with", default="nothing")
|
||||||
|
|
||||||
|
|
||||||
@app.post("/form/")
|
@app.post("/form/")
|
||||||
|
|
@ -32,6 +33,7 @@ def test_send_all_data():
|
||||||
"lastname": "Sanchez",
|
"lastname": "Sanchez",
|
||||||
"age": "70",
|
"age": "70",
|
||||||
"tags": ["plumbus", "citadel"],
|
"tags": ["plumbus", "citadel"],
|
||||||
|
"with": "something",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
|
|
@ -40,6 +42,7 @@ def test_send_all_data():
|
||||||
"lastname": "Sanchez",
|
"lastname": "Sanchez",
|
||||||
"age": 70,
|
"age": 70,
|
||||||
"tags": ["plumbus", "citadel"],
|
"tags": ["plumbus", "citadel"],
|
||||||
|
"with": "something",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -51,6 +54,7 @@ def test_defaults():
|
||||||
"lastname": "Sanchez",
|
"lastname": "Sanchez",
|
||||||
"age": None,
|
"age": None,
|
||||||
"tags": ["foo", "bar"],
|
"tags": ["foo", "bar"],
|
||||||
|
"with": "nothing",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -100,13 +104,13 @@ def test_no_data():
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": ["body", "username"],
|
"loc": ["body", "username"],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": {"tags": ["foo", "bar"]},
|
"input": {"tags": ["foo", "bar"], "with": "nothing"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "missing",
|
"type": "missing",
|
||||||
"loc": ["body", "lastname"],
|
"loc": ["body", "lastname"],
|
||||||
"msg": "Field required",
|
"msg": "Field required",
|
||||||
"input": {"tags": ["foo", "bar"]},
|
"input": {"tags": ["foo", "bar"], "with": "nothing"},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue