Skip to content

Commit e26f940

Browse files
♻️ Refactor serialize_response parameter name (fastapi#1031)
1 parent 1ce6788 commit e26f940

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

fastapi/routing.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
async def serialize_response(
5151
*,
5252
field: ModelField = None,
53-
response: Response,
53+
response_content: Any,
5454
include: Union[SetIntStr, DictIntStrAny] = None,
5555
exclude: Union[SetIntStr, DictIntStrAny] = set(),
5656
by_alias: bool = True,
@@ -59,16 +59,18 @@ async def serialize_response(
5959
) -> Any:
6060
if field:
6161
errors = []
62-
if exclude_unset and isinstance(response, BaseModel):
62+
if exclude_unset and isinstance(response_content, BaseModel):
6363
if PYDANTIC_1:
64-
response = response.dict(exclude_unset=exclude_unset)
64+
response_content = response_content.dict(exclude_unset=exclude_unset)
6565
else:
66-
response = response.dict(skip_defaults=exclude_unset) # pragma: nocover
66+
response_content = response_content.dict(
67+
skip_defaults=exclude_unset
68+
) # pragma: nocover
6769
if is_coroutine:
68-
value, errors_ = field.validate(response, {}, loc=("response",))
70+
value, errors_ = field.validate(response_content, {}, loc=("response",))
6971
else:
7072
value, errors_ = await run_in_threadpool(
71-
field.validate, response, {}, loc=("response",)
73+
field.validate, response_content, {}, loc=("response",)
7274
)
7375
if isinstance(errors_, ErrorWrapper):
7476
errors.append(errors_)
@@ -84,7 +86,7 @@ async def serialize_response(
8486
exclude_unset=exclude_unset,
8587
)
8688
else:
87-
return jsonable_encoder(response)
89+
return jsonable_encoder(response_content)
8890

8991

9092
async def run_endpoint_function(
@@ -151,7 +153,7 @@ async def app(request: Request) -> Response:
151153
return raw_response
152154
response_data = await serialize_response(
153155
field=response_field,
154-
response=raw_response,
156+
response_content=raw_response,
155157
include=response_model_include,
156158
exclude=response_model_exclude,
157159
by_alias=response_model_by_alias,

0 commit comments

Comments
 (0)