@@ -301,35 +301,37 @@ async def _execute_func( # pylint: disable=too-many-positional-arguments
301
301
302
302
user_settings = execution_context .user_settings
303
303
system_settings = execution_context .system_settings
304
+ raised_warnings : list = []
305
+ custom_headers : Optional [dict [str , Any ]] = None
304
306
305
- with catch_warnings (record = True ) as warning_list :
306
- # If we're on Jupyter we need to pop here because we will lose "chart" after
307
- # ParametersBuilder.build. This needs to be fixed in a way that chart is
308
- # added to the function signature and shared for jupyter and api
309
- # We can check in the router decorator if the given function has a chart
310
- # in the charting extension then we add it there. This way we can remove
311
- # the chart parameter from the commands.py and package_builder, it will be
312
- # added to the function signature in the router decorator
313
- chart = kwargs .pop ("chart" , False )
314
-
315
- kwargs = ParametersBuilder .build (
316
- args = args ,
317
- execution_context = execution_context ,
318
- func = func ,
319
- kwargs = kwargs ,
320
- )
307
+ try :
308
+ with catch_warnings (record = True ) as warning_list :
309
+ # If we're on Jupyter we need to pop here because we will lose "chart" after
310
+ # ParametersBuilder.build. This needs to be fixed in a way that chart is
311
+ # added to the function signature and shared for jupyter and api
312
+ # We can check in the router decorator if the given function has a chart
313
+ # in the charting extension then we add it there. This way we can remove
314
+ # the chart parameter from the commands.py and package_builder, it will be
315
+ # added to the function signature in the router decorator
316
+ chart = kwargs .pop ("chart" , False )
317
+
318
+ kwargs = ParametersBuilder .build (
319
+ args = args ,
320
+ execution_context = execution_context ,
321
+ func = func ,
322
+ kwargs = kwargs ,
323
+ )
321
324
322
- # If we're on the api we need to remove "chart" here because the parameter is added on
323
- # commands.py and the function signature does not expect "chart"
324
- kwargs .pop ("chart" , None )
325
- # We also pop custom headers
326
- model_headers = system_settings .api_settings .custom_headers or {}
327
- custom_headers = {
328
- name : kwargs .pop (name .replace ("-" , "_" ), default )
329
- for name , default in model_headers .items () or {}
330
- } or None
325
+ # If we're on the api we need to remove "chart" here because the parameter is added on
326
+ # commands.py and the function signature does not expect "chart"
327
+ kwargs .pop ("chart" , None )
328
+ # We also pop custom headers
329
+ model_headers = system_settings .api_settings .custom_headers or {}
330
+ custom_headers = {
331
+ name : kwargs .pop (name .replace ("-" , "_" ), default )
332
+ for name , default in model_headers .items () or {}
333
+ } or None
331
334
332
- try :
333
335
obbject = await cls ._command (func , kwargs )
334
336
# The output might be from a router command with 'no_validate=True'
335
337
# It might be of a different type than OBBject.
@@ -350,32 +352,33 @@ async def _execute_func( # pylint: disable=too-many-positional-arguments
350
352
if chart and obbject .results :
351
353
cls ._chart (obbject , ** kwargs )
352
354
353
- if warning_list :
355
+ raised_warnings = warning_list if warning_list else []
356
+ finally :
357
+ if raised_warnings :
358
+ if isinstance (obbject , OBBject ):
359
+ obbject .warnings = []
360
+ for w in raised_warnings :
354
361
if isinstance (obbject , OBBject ):
355
- obbject .warnings = []
356
- for w in warning_list :
357
- if isinstance (obbject , OBBject ):
358
- obbject .warnings .append (cast_warning (w ))
359
- if user_settings .preferences .show_warnings :
360
- showwarning (
361
- message = w .message ,
362
- category = w .category ,
363
- filename = w .filename ,
364
- lineno = w .lineno ,
365
- file = w .file ,
366
- line = w .line ,
367
- )
368
- finally :
369
- ls = LoggingService (system_settings , user_settings )
370
- ls .log (
371
- user_settings = user_settings ,
372
- system_settings = system_settings ,
373
- route = route ,
374
- func = func ,
375
- kwargs = kwargs ,
376
- exec_info = exc_info (),
377
- custom_headers = custom_headers ,
378
- )
362
+ obbject .warnings .append (cast_warning (w ))
363
+ if user_settings .preferences .show_warnings :
364
+ showwarning (
365
+ message = w .message ,
366
+ category = w .category ,
367
+ filename = w .filename ,
368
+ lineno = w .lineno ,
369
+ file = w .file ,
370
+ line = w .line ,
371
+ )
372
+ ls = LoggingService (system_settings , user_settings )
373
+ ls .log (
374
+ user_settings = user_settings ,
375
+ system_settings = system_settings ,
376
+ route = route ,
377
+ func = func ,
378
+ kwargs = kwargs ,
379
+ exec_info = exc_info (),
380
+ custom_headers = custom_headers ,
381
+ )
379
382
380
383
return obbject
381
384
0 commit comments