# Buggy code
def run(
    self,
    header,
    body,
    partial_args,
    app=None,
    interval=None,
    countdown=1,
    max_retries=None,
    eager=False,
    task_id=None,
    **options,
):
    app = app or self._get_app(body)
    group_id = header.options.get("task_id") or uuid()
    root_id = body.options.get("root_id")
    body.chord_size = self.__length_hint__()
    options = dict(self.options, **options) if options else self.options
    if options:
        options.pop("task_id", None)
        body.options.update(options)

    results = header.freeze(group_id=group_id, chord=body, root_id=root_id).results
    bodyres = body.freeze(task_id, root_id=root_id)

    # Chains should not be passed to the header tasks. See #3771
    options.pop("chain", None)

    parent = app.backend.apply_chord(
        header,
        partial_args,
        group_id,
        body,
        interval=interval,
        countdown=countdown,
        options=options,
        max_retries=max_retries,
        result=results,
    )
    bodyres.parent = parent
    return bodyres


# Traceback (KeyError)
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

# Fixed code
def run(
    self,
    header,
    body,
    partial_args,
    app=None,
    interval=None,
    countdown=1,
    max_retries=None,
    eager=False,
    task_id=None,
    **options,
):
    app = app or self._get_app(body)
    group_id = header.options.get("task_id") or uuid()
    root_id = body.options.get("root_id")
    body.chord_size = self.__length_hint__()
    options = dict(self.options, **options) if options else self.options
    if options:
        options.pop("task_id", None)
        body.options.update(options)

    results = header.freeze(group_id=group_id, chord=body, root_id=root_id).results
    bodyres = body.freeze(task_id, root_id=root_id)

    # Chains should not be passed to the header tasks. See #3771
    options.pop("chain", None)
    # Neither should chords, for deeply nested chords to work
    options.pop("chord", None)

    parent = app.backend.apply_chord(
        header,
        partial_args,
        group_id,
        body,
        interval=interval,
        countdown=countdown,
        options=options,
        max_retries=max_retries,
        result=results,
    )
    bodyres.parent = parent
    return bodyres