Skip to content

Commit 88d4f2c

Browse files
authored
🐛 Fix form field regression (fastapi#12194)
1 parent 0fc6e34 commit 88d4f2c

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

fastapi/dependencies/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ async def process_fn(
788788
tg.start_soon(process_fn, sub_value.read)
789789
value = serialize_sequence_value(field=field, value=results)
790790
if value is not None:
791-
values[field.name] = value
791+
values[field.alias] = value
792792
for key, value in received_body.items():
793793
if key not in values:
794794
values[key] = value

tests/test_forms_single_model.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dirty_equals import IsDict
44
from fastapi import FastAPI, Form
55
from fastapi.testclient import TestClient
6-
from pydantic import BaseModel
6+
from pydantic import BaseModel, Field
77
from typing_extensions import Annotated
88

99
app = FastAPI()
@@ -14,6 +14,7 @@ class FormModel(BaseModel):
1414
lastname: str
1515
age: Optional[int] = None
1616
tags: List[str] = ["foo", "bar"]
17+
alias_with: str = Field(alias="with", default="nothing")
1718

1819

1920
@app.post("/form/")
@@ -32,6 +33,7 @@ def test_send_all_data():
3233
"lastname": "Sanchez",
3334
"age": "70",
3435
"tags": ["plumbus", "citadel"],
36+
"with": "something",
3537
},
3638
)
3739
assert response.status_code == 200, response.text
@@ -40,6 +42,7 @@ def test_send_all_data():
4042
"lastname": "Sanchez",
4143
"age": 70,
4244
"tags": ["plumbus", "citadel"],
45+
"with": "something",
4346
}
4447

4548

@@ -51,6 +54,7 @@ def test_defaults():
5154
"lastname": "Sanchez",
5255
"age": None,
5356
"tags": ["foo", "bar"],
57+
"with": "nothing",
5458
}
5559

5660

@@ -100,13 +104,13 @@ def test_no_data():
100104
"type": "missing",
101105
"loc": ["body", "username"],
102106
"msg": "Field required",
103-
"input": {"tags": ["foo", "bar"]},
107+
"input": {"tags": ["foo", "bar"], "with": "nothing"},
104108
},
105109
{
106110
"type": "missing",
107111
"loc": ["body", "lastname"],
108112
"msg": "Field required",
109-
"input": {"tags": ["foo", "bar"]},
113+
"input": {"tags": ["foo", "bar"], "with": "nothing"},
110114
},
111115
]
112116
}

0 commit comments

Comments
 (0)