I have a chain of tasks that a celery worker runs. When a task is finished the chain carries forward the result of that task to the next task as a (positional) argument. Each task has it's own arguments + *args to handle the carried forward arguments. The problem is that I want to use keyword argument for the arguments of the task but those carried forward arguments are just positional arguments. The following code is just a simple example to show my problem without use of celery chains:
def test_func(data1,*args):
print(data1, '\t', args)
def b():
return {'data2':'b'}
test_func(data1='a', b())
I know that this generates "SyntaxError: positional argument follows keyword argument" because the first argument is using the argument name whereas the second one doesn't.
If I know how to properly return the result of function b() then my problem will be solved. That is, to return the result of b() in a way that b() is considered as a keyword argument when calling
test_func(data1='a', b())
UPDATE: It turned out celery chains carry over the results of each task to the first argument of the next task in the chain, not the last argument. This was my bad as I was new to celery chains. Therefore, I just switched the place of positional and keyword arguments in the function's header and my problem was solved as bellow:
def test_func(data1, data2):
print(data1, '\t', data2)
def b():
return 'b'
test_func(b(),data2='a')
As Python allows to have a keyword argument after a positional argument, everything turned out to be smoothly running.
Thanks to @MatiasCicero and @C.Nivs for their answers.