return local_context._executing_async[-1] raise errors.NotInContextError("Not in an _ExecutionContext.") def get_current_context(): """Return a reference to the current Context object. """ local_context = _local.get_local_context() if local_context.registry: return local_context.registry[-1] raise errors.NotInContextError("Not in a Context.") def get_current_async_with_context(): """Return a reference to the currently executing Async job object and it's triggering context. Return None for the async if not in an Async job and None for the context if the Async was not triggered within a context. """ async = get_current_async() if not async: return None, None if not async.context_id: return async, None return async, Context.load(async.context_id)