]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
:recycle: Refactor serialize_response parameter name (#1031)
authorPatrick McKenna <patrick.b.mckenna@gmail.com>
Sat, 29 Feb 2020 16:33:02 +0000 (08:33 -0800)
committerGitHub <noreply@github.com>
Sat, 29 Feb 2020 16:33:02 +0000 (17:33 +0100)
fastapi/routing.py

index 05919be662ca3ca65597deda348b72faeacc4d6a..d5211c4892d6bfb621cadfa15172156b46b07448 100644 (file)
@@ -50,7 +50,7 @@ except ImportError:  # pragma: nocover
 async def serialize_response(
     *,
     field: ModelField = None,
-    response: Response,
+    response_content: Any,
     include: Union[SetIntStr, DictIntStrAny] = None,
     exclude: Union[SetIntStr, DictIntStrAny] = set(),
     by_alias: bool = True,
@@ -59,16 +59,18 @@ async def serialize_response(
 ) -> Any:
     if field:
         errors = []
-        if exclude_unset and isinstance(response, BaseModel):
+        if exclude_unset and isinstance(response_content, BaseModel):
             if PYDANTIC_1:
-                response = response.dict(exclude_unset=exclude_unset)
+                response_content = response_content.dict(exclude_unset=exclude_unset)
             else:
-                response = response.dict(skip_defaults=exclude_unset)  # pragma: nocover
+                response_content = response_content.dict(
+                    skip_defaults=exclude_unset
+                )  # pragma: nocover
         if is_coroutine:
-            value, errors_ = field.validate(response, {}, loc=("response",))
+            value, errors_ = field.validate(response_content, {}, loc=("response",))
         else:
             value, errors_ = await run_in_threadpool(
-                field.validate, response, {}, loc=("response",)
+                field.validate, response_content, {}, loc=("response",)
             )
         if isinstance(errors_, ErrorWrapper):
             errors.append(errors_)
@@ -84,7 +86,7 @@ async def serialize_response(
             exclude_unset=exclude_unset,
         )
     else:
-        return jsonable_encoder(response)
+        return jsonable_encoder(response_content)
 
 
 async def run_endpoint_function(
@@ -151,7 +153,7 @@ def get_request_handler(
                 return raw_response
             response_data = await serialize_response(
                 field=response_field,
-                response=raw_response,
+                response_content=raw_response,
                 include=response_model_include,
                 exclude=response_model_exclude,
                 by_alias=response_model_by_alias,