# Buggy code
def apply_async(
    self,
    args=(),
    kwargs={},
    task_id=None,
    producer=None,
    publisher=None,
    connection=None,
    router=None,
    result_cls=None,
    **options,
):
    kwargs = kwargs or {}
    args = tuple(args) + tuple(self.args) if args and not self.immutable else self.args
    body = kwargs.pop("body", None) or self.kwargs["body"]
    kwargs = dict(self.kwargs["kwargs"], **kwargs)
    body = body.clone(**options)
    app = self._get_app(body)
    tasks = (
        self.tasks.clone()
        if isinstance(self.tasks, group)
        else group(self.tasks, app=app)
    )
    if app.conf.task_always_eager:
        return self.apply(args, kwargs, body=body, task_id=task_id, **options)
    if len(self.tasks) == 1:
        # chord([A], B) can be optimized as A | B
        # - Issue #3323
        return (
            (self.tasks[0] | body)
            .set(task_id=task_id)
            .apply_async(args, kwargs, **options)
        )
    # chord([A, B, ...], C)
    return self.run(tasks, body, args, task_id=task_id, **options)


# 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 apply_async(
    self,
    args=(),
    kwargs={},
    task_id=None,
    producer=None,
    publisher=None,
    connection=None,
    router=None,
    result_cls=None,
    **options,
):
    kwargs = kwargs or {}
    args = tuple(args) + tuple(self.args) if args and not self.immutable else self.args
    body = kwargs.pop("body", None) or self.kwargs["body"]
    kwargs = dict(self.kwargs["kwargs"], **kwargs)
    body = body.clone(**options)
    app = self._get_app(body)
    tasks = (
        self.tasks.clone()
        if isinstance(self.tasks, group)
        else group(self.tasks, app=app)
    )
    if app.conf.task_always_eager:
        return self.apply(args, kwargs, body=body, task_id=task_id, **options)
    # chord([A, B, ...], C)
    return self.run(tasks, body, args, task_id=task_id, **options)