@@ -87,6 +87,19 @@ async def serialize_response(
87
87
return jsonable_encoder (response )
88
88
89
89
90
+ async def run_endpoint_function (
91
+ * , dependant : Dependant , values : Dict [str , Any ], is_coroutine : bool
92
+ ) -> Any :
93
+ # Only called by get_request_handler. Has been split into its own function to
94
+ # facilitate profiling endpoints, since inner functions are harder to profile.
95
+ assert dependant .call is not None , "dependant.call must be a function"
96
+
97
+ if is_coroutine :
98
+ return await dependant .call (** values )
99
+ else :
100
+ return await run_in_threadpool (dependant .call , ** values )
101
+
102
+
90
103
def get_request_handler (
91
104
dependant : Dependant ,
92
105
body_field : ModelField = None ,
@@ -128,11 +141,10 @@ async def app(request: Request) -> Response:
128
141
if errors :
129
142
raise RequestValidationError (errors , body = body )
130
143
else :
131
- assert dependant .call is not None , "dependant.call must be a function"
132
- if is_coroutine :
133
- raw_response = await dependant .call (** values )
134
- else :
135
- raw_response = await run_in_threadpool (dependant .call , ** values )
144
+ raw_response = await run_endpoint_function (
145
+ dependant = dependant , values = values , is_coroutine = is_coroutine
146
+ )
147
+
136
148
if isinstance (raw_response , Response ):
137
149
if raw_response .background is None :
138
150
raw_response .background = background_tasks
0 commit comments