From 9abd18aa13360005130bc6de5ce5a509a5f0cdcd Mon Sep 17 00:00:00 2001 From: Gen Xu Date: Wed, 15 Sep 2021 03:10:36 -0700 Subject: [PATCH] add locals for async exceptions --- src/dependency_injector/providers.pxd | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/dependency_injector/providers.pxd b/src/dependency_injector/providers.pxd index d1beb771..6617dfe4 100644 --- a/src/dependency_injector/providers.pxd +++ b/src/dependency_injector/providers.pxd @@ -477,6 +477,8 @@ cdef inline void __async_prepare_args_kwargs_callback( for value, (key, _) in zip(result, future_args_kwargs): args[key] = value except Exception as exception: + exception.__traceback__.tb_frame.f_locals.clear() + exception.__traceback__.tb_frame.f_locals.update(locals()) future_result.set_exception(exception) else: future_result.set_result(args) @@ -525,6 +527,8 @@ cdef inline void __async_inject_attributes_callback(object future_result, object for name, value in attributes.items(): setattr(instance, name, value) except Exception as exception: + exception.__traceback__.tb_frame.f_locals.clear() + exception.__traceback__.tb_frame.f_locals.update(locals()) future_result.set_exception(exception) else: future_result.set_result(instance) @@ -577,16 +581,18 @@ cdef inline object __call( return future_result try: return call(*args, **kwargs) - except Exception as e: - e.__traceback__.tb_frame.f_locals.clear() - e.__traceback__.tb_frame.f_locals.update(locals()) - raise e + except Exception as exception: + exception.__traceback__.tb_frame.f_locals.clear() + exception.__traceback__.tb_frame.f_locals.update(locals()) + raise exception cdef inline void __async_call_callback(object future_result, object call, object future): try: args, kwargs = future.result() result = call(*args, **kwargs) except Exception as exception: + exception.__traceback__.tb_frame.f_locals.clear() + exception.__traceback__.tb_frame.f_locals.update(locals()) future_result.set_exception(exception) else: if __is_future_or_coroutine(result): @@ -600,6 +606,8 @@ cdef inline object __async_result_callback(object future_result, object future): try: result = future.result() except Exception as exception: + exception.__traceback__.tb_frame.f_locals.clear() + exception.__traceback__.tb_frame.f_locals.update(locals()) future_result.set_exception(exception) else: future_result.set_result(result)