From 6da92aa583850e0457fb92a59ebcdf4289869dab Mon Sep 17 00:00:00 2001 From: Daniel Debonzi Date: Tue, 26 Sep 2017 12:18:05 -0300 Subject: [PATCH] Fix exception when using task decorated with bind_callback_meta passing no callback task. --- crossover/__init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crossover/__init__.py b/crossover/__init__.py index 78b5924..ac779cd 100644 --- a/crossover/__init__.py +++ b/crossover/__init__.py @@ -42,27 +42,33 @@ def _build_callback(task): def callback(auto_callback=False, bind_callback_meta=False): def _executor(func): - def wrapped(*args, **kwargs): + def wrapped(**kwargs): if 'callback' in kwargs: _callback = kwargs.pop('callback') if auto_callback: - return CallBack(_callback)(result=func(**kwargs)) + CallBack(_callback)(result=func(**kwargs)) elif bind_callback_meta: func(_callback, **kwargs) else: func(**kwargs) return - func(**kwargs) + if bind_callback_meta: # and not 'callback' in kwargs + func(None, **kwargs) + else: + func(**kwargs) return wrapped return _executor class CallBack(object): def __init__(self, callback_data): - self.requester = _Requester(callback_data.get('broker'), callback_data.get('task')) + self.requester = None + if callback_data: + self.requester = _Requester(callback_data.get('broker'), callback_data.get('task')) def __call__(self, *args, **kwargs): - self.requester(*args, **kwargs) + if self.requester: + self.requester(*args, **kwargs) class _Requester(object):