komuw / wiji

Wiji is an asyncio distributed task processor/queue.
MIT License
4 stars 1 forks source link

parent of chained task returning tuple #29

Open komuw opened 5 years ago

komuw commented 5 years ago

Currently, if we have a chained task, we use the return_value of the parent to queue the child: https://github.com/komuw/wiji/blob/e9da8eff13e08dfc53acad95c4a7642dad994881/wiji/worker.py#L183-L186

However, what happens if return_value is a tuple?
I think in that case, we ought to;

await self.the_task.chain.delay(*return_value)

ie only if return_value is a tuple

komuw commented 5 years ago
def cool():
    return 34, "name"

def run(*args, **kwargs):
    print(args, kwargs)

return_value = cool()

## what we are currently doing
>>> run(return_value)
((34, 'name'),) {}

## versus what I think we ought to do
>>> run(*return_value)
(34, 'name') {}
>>>
komuw commented 5 years ago

however, think of situation where:

import typing
def run(value: typing.Tuple, **kwargs):
    print(value, kwargs)

ie, run expects a tuple as it's first argument.

in such a case

## what we are currently doing
>>> run(return_value)
(34, 'name') {}

## versus what I think we ought to do
>>> run(*return_value)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: run() takes 1 positional argument but 2 were given

so we haven't made the situation any better.

komuw commented 5 years ago

this is the way celery does it; https://github.com/celery/celery/blob/e2161783e1a4cb021cd37d5df8581f7729f9095c/celery/app/trace.py#L439-L446

komuw commented 5 years ago

I think, we'll leave it as is for now.

komuw commented 5 years ago

I'm labelling this as a bug since it might be surprising for people using wiji.