Skip to content

Nested chord are failling with KeyError, if inner chord consists of one task #3885

Closed

Description

@elysium31

Tested on celery v4.0.2

I have the following set of tasks, nested chord of chords. One inner chord has only one task (i don't know exact number of tasks beforehand, they are compound in runtime). And it is falling with exception KeyError: 0

chord(
     [
         chord([taskA1.s(), taskA2.s()], taskC.si()),
         chord([taskB.s()], taskC.si())
     ], 
     taskD.si()
).delay()
Traceback (most recent call last):
  File "<console>", line 6, in <module>
  File "/home/maksym/projects/python_ve/lib/python3.4/site-packages/celery/canvas.py", line 182, in delay
    return self.apply_async(partial_args, partial_kwargs)
  File "/home/maksym/projects/python_ve/lib/python3.4/site-packages/celery/canvas.py", line 1245, in apply_async
    return self.run(tasks, body, args, task_id=task_id, **options)
  File "/home/maksym/projects/python_ve/lib/python3.4/site-packages/celery/canvas.py", line 1287, in run
    result=results)
  File "/home/maksym/projects/python_ve/lib/python3.4/site-packages/celery/backends/redis.py", line 245, in apply_chord
    return header(*partial_args, **options or {})
  File "/home/maksym/projects/python_ve/lib/python3.4/site-packages/celery/canvas.py", line 962, in __call__
    return self.apply_async(partial_args, **options)
  File "/home/maksym/projects/python_ve/lib/python3.4/site-packages/celery/canvas.py", line 987, in apply_async
    args=args, kwargs=kwargs, **options))
  File "/home/maksym/projects/python_ve/lib/python3.4/site-packages/celery/canvas.py", line 1063, in _apply_tasks
    **options)
  File "/home/maksym/projects/python_ve/lib/python3.4/site-packages/celery/canvas.py", line 1242, in apply_async
    return (self.tasks[0] | body).set(task_id=task_id).apply_async(
KeyError: 0

I assume self.task[0] should be replaced with self.task, am i right?

Activity

  1. thedrow commented on Apr 15, 2017

    @thedrow
    Contributor

    @robpogorzelski Do you mind describing your approach? I'll see if I can give it a go...

  2. e3b0c442 commented on May 26, 2017

    @e3b0c442

    One inner chord has only one task

    I think this may be the key. I dynamically generate my chords and they may have anywhere from 1-∞ members, and I noticed that when the chord has only one member, the result is not passed to the callback wrapped in a list.

    Upon looking at the release notes, I discovered the following:

    A chord where the header group only consists of a single task is now turned into a simple chain.

    I think this conversion is failing to wrap the result in a list as would happen if there were multiple tasks in the header. If your callback code is expecting to handle that list, you would run into errors. Complicating matters is the case (like mine) where the chord task result is itself a list.

    Not sure if this specific finding has been reported elsewhere, I found this bug in that search.

  3. JioHooney commented on Feb 13, 2018

    @JioHooney

    I have same problem.
    Has this problem been resolved?

  4. thedrow commented on Feb 13, 2018

    @thedrow
    Contributor

    Yes in master. Release is coming soon. See #4387 for details.

  5. JioHooney commented on Feb 13, 2018

    @JioHooney

    @thedrow
    Thanks for the answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions