You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
the chord function work not well with just one header task #3597
will raise error: ValueError: AsyncResult requires valid id, not <type 'NoneType'>
## Actual behavior
File "/home/meron/workspace/xiaolusys/ve10/local/lib/python2.7/site-packages/celery/canvas.py", line 1200, in __call__
return self.apply_async((), {'body': body} if body else {}, **options)
File "/home/meron/workspace/xiaolusys/ve10/local/lib/python2.7/site-packages/celery/canvas.py", line 1246, in apply_async
args, kwargs, **options)
File "/home/meron/workspace/xiaolusys/ve10/local/lib/python2.7/site-packages/celery/canvas.py", line 567, in apply_async
dict(self.options, **options) if options else self.options))
File "/home/meron/workspace/xiaolusys/ve10/local/lib/python2.7/site-packages/celery/canvas.py", line 586, in run
task_id, group_id, chord,
File "/home/meron/workspace/xiaolusys/ve10/local/lib/python2.7/site-packages/celery/canvas.py", line 679, in prepare_steps
res = task.freeze(root_id=root_id)
File "/home/meron/workspace/xiaolusys/ve10/local/lib/python2.7/site-packages/celery/canvas.py", line 284, in freeze
return self.AsyncResult(tid)
File "/home/meron/workspace/xiaolusys/ve10/local/lib/python2.7/site-packages/celery/app/task.py", line 747, in AsyncResult
task_name=self.name, **kwargs)
File "/home/meron/workspace/xiaolusys/ve10/local/lib/python2.7/site-packages/celery/result.py", line 90, in __init__
'AsyncResult requires valid id, not {0}'.format(type(id)))
I get this a lot. Is there a work around? My solution is to check if there is only one element and in that case create a chain instead. The argument passed into the next task in the chain (or following the chord) is then converted to a list.
# entry point
@app.task
def task1(arg):
# schedule loads of tasks, or just one - depends on input
mygroup = group(task2.s(a) for a in arg)
if len(mygroup) == 1:
return chain(mygroup, task3.s('there was only one')).delay()
else:
return chord(mygroup)(task3.s('there were more than one'))
@app.task
def task2(arg):
# prepare data for processing
return arg
# this task expects a list
@app.task
def task3(arg1, arg2):
print(arg2)
if not isinstance(arg1, list):
arg1 = [arg1]
# process arg1 list
Where single element chords are turned into a simple chain. I'm not sure the rationale for the patch still holds with this issue in mind but I would leave it for the author to answer: @ask any comments in regards to the added complexity with dynamic chord sizes?
Also affected here. My solution was to check in the chord callback if results is a list or not and make it one if needed, but again that only solves one of the issues this leads to.
This is very annoying indeed, and have been biting me randomly the last couple of days..
Is everyone using the @OndrejIT hotfix? Is there a better way of doing this?
@xeor I've worked around this by implementing a custom chord helper. It's ugly and I'd prefer not to use it, but it's worked fine in production for almost a year now. Hope this helps someone else!
importceleryas_celerydefchord(header, callback):
"""A smart wrapper around `celery.chord` that handles several edge cases. There are a two subtle gotchas that happen with the default implementation of `celery.chord`: - If the header is empty, the callback never gets executed. This wrapper ensures that the callback *does* get executed. - If the header has only one task, then celery throws a `ValueError`: https://github.com/celery/celery/issues/3597 Args: header (List[Signature]): A list of task `Signature` objects. callback (Signature): The `Signature` of a task that should be executed after all the tasks in the header. """ifnotheader:
ifcallback:
callback.delay()
eliflen(header) ==1:
ifcallback:
_celery.chain(header[0], callback).delay()
else:
header[0].delay()
else:
ifcallback:
_celery.chord(header)(callback)
else:
_celery.group(header).delay()
Activity
Zatte commentedon Nov 17, 2016
I've also experienced this issues (or at least a similar one through implicit chord transformation).
When only 1 element is added to a chord it doesn't wrap the single value in a list.
=>
Note that the first element is [3] and not the expected [[3]]
Verified with both Redis and RabbitMQ brooker but only Redis result backend.
Environment
Python 2.7.6
Celery 4.0.0
Redis 3.2.5
ggstuart commentedon Nov 23, 2016
I get this a lot. Is there a work around? My solution is to check if there is only one element and in that case create a chain instead. The argument passed into the next task in the chain (or following the chord) is then converted to a list.
Zatte commentedon Nov 23, 2016
Did some quick digging; It seems the issues was introduced with
867a3aa
as a fix to
#3323
https://github.com/celery/celery/blob/master/celery/canvas.py#L388-L391
Where single element chords are turned into a simple chain. I'm not sure the rationale for the patch still holds with this issue in mind but I would leave it for the author to answer: @ask any comments in regards to the added complexity with dynamic chord sizes?
mattjegan commentedon Feb 14, 2017
Is there any progress on this?
a-pertsev commentedon Apr 9, 2017
+1 for fix, the current behaviour is totally broken, chord([A], B) is not equals to A | B
=/
canassa commentedon Apr 14, 2017
I must also add that this issue also affects the newly introduced
add_to_chordmethodrholloway commentedon May 30, 2017
Also affected here. My solution was to check in the chord callback if results is a list or not and make it one if needed, but again that only solves one of the issues this leads to.
OndrejIT commentedon Jun 3, 2017
+1 for fix.
Hotfix:
if len(tasks) == 1: tasks.append(blank_task.s())xeor commentedon Nov 7, 2017
This is very annoying indeed, and have been biting me randomly the last couple of days..
Is everyone using the @OndrejIT hotfix? Is there a better way of doing this?
calvinwyoung commentedon Nov 7, 2017
@xeor I've worked around this by implementing a custom
chordhelper. It's ugly and I'd prefer not to use it, but it's worked fine in production for almost a year now. Hope this helps someone else!Fix length-1 and nested chords (#4393 #4055 #3885 #3597 #3574 #3323) (#…