Skip to content

AttributeError thrown when using link_error/on_error on a rewritten chain when task_allow_error_cb_on_chord_header is enabled #8456

@astei

Description

@astei

Checklist

  • I have verified that the issue exists against the main branch of Celery.
  • This has already been asked to the discussions forum first.
  • I have read the relevant section in the
    contribution guide
    on reporting bugs.
  • I have checked the issues list
    for similar or identical bug reports.
  • I have checked the pull requests list
    for existing proposed fixes.
  • I have checked the commit log
    to find out if the bug was already fixed in the main branch.
  • I have included all related issues and possible duplicate issues
    in this issue (If there are none, check this box anyway).

Mandatory Debugging Information

  • I have included the output of celery -A proj report in the issue.
    (if you are not able to do this, then at least specify the Celery
    version affected).
  • I have verified that the issue exists against the main branch of Celery.
  • I have included the contents of pip freeze in the issue.
  • I have included all the versions of all the external dependencies required
    to reproduce this bug.

Optional Debugging Information

  • I have tried reproducing the issue on more than one Python version
    and/or implementation.
  • I have tried reproducing the issue on more than one message broker and/or
    result backend.
  • I have tried reproducing the issue on more than one version of the message
    broker and/or result backend.
  • I have tried reproducing the issue on more than one operating system.
  • I have tried reproducing the issue on more than one workers pool.
  • I have tried reproducing the issue with autoscaling, retries,
    ETA/Countdown & rate limits disabled.
  • I have tried reproducing the issue after downgrading
    and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

Possible Duplicates

  • None

Environment & Settings

Celery version: 5.3.1 (emerald-rush)

celery report Output:

software -> celery:5.3.1 (emerald-rush) kombu:5.3.1 py:3.10.7
            billiard:4.1.0 redis:5.0.0
platform -> system:Darwin arch:64bit
            kernel version:22.6.0 imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:redis results:redis://localhost/

broker_url: 'redis://localhost:6379//'
result_backend: 'redis://localhost/'
deprecated_settings: None
task_allow_error_cb_on_chord_header: True

Steps to Reproduce

Required Dependencies

  • Minimal Python Version: 3.10.x
  • Minimal Celery Version: 5.3.1
  • Minimal Kombu Version: N/A
  • Minimal Broker Version: N/A
  • Minimal Result Backend Version: N/A
  • Minimal OS and/or Kernel Version: N/A (we've reproduced with our own deployment on Linux, and locally on macOS)
  • Minimal Broker Client Version: N/A
  • Minimal Result Backend Client Version: N/A

Python Packages

pip freeze Output:

amqp==5.1.1
async-timeout==4.0.3
billiard==4.1.0
celery @ git+https://github.com/celery/celery.git@8ae0b229596cc8aeea4fb71020d9358a59338e08
click==8.1.7
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.3.0
kombu==5.3.1
prompt-toolkit==3.0.39
python-dateutil==2.8.2
redis==5.0.0
six==1.16.0
tzdata==2023.3
vine==5.0.0
wcwidth==0.2.6

Other Dependencies

Details

N/A

Minimally Reproducible Test Case

Details

from celery import Celery, chain, group, chord

app = Celery('tasks', broker='redis://localhost/', backend='redis://localhost/')
app.conf.task_allow_error_cb_on_chord_header = True


@app.task
def fake_work_unit(x):
    raise Exception


@app.task
def nothing_work_unit():
    return "hi"


@app.task
def fake_error_handler(*args):
    print("oops")


def test():
    f = app.signature(
        "test_celery.nothing_work_unit",
        immutable=True,
    )

    f2 = app.signature(
        "test_celery.fake_error_handler",
    )

    # This formulation works correctly...
    # chain(
    #    f.on_error(f2),
    #    group(
    #        app.signature(
    #            "test_celery.fake_work_unit",
    #            args=(1,),
    #            immutable=True,
    #        ),
    #        app.signature(
    #            "test_celery.fake_work_unit",
    #            args=(2,),
    #            immutable=True,
    #        ),
    #    ).on_error(f2),
    #    f.on_error(f2),
    # ).apply_async()

    # ...but not this one.
    chain(
        f,
        group(
            app.signature(
                "test_celery.fake_work_unit",
                args=(1,),
                immutable=True,
            ),
            app.signature(
                "test_celery.fake_work_unit",
                args=(2,),
                immutable=True,
            ),
        ),
        f,
    ).on_error(f2).apply_async()

Run celery -A test_celery worker and then in a different shell:

from test_celery import test
test()

Then comment out the second formulation and uncomment the first. Notice that it works as intended.

This test case also works if you disable task_allow_error_cb_on_chord_header, or remove the on_error/link_error call, but either will result in the error handler being invoked.

Expected Behavior

Either formulation described should work. The second formulation should not be throwing AttributeError.

The intended result is:

  • test_celery.nothing_work_unit succeeds.
  • One of the test_celery.fake_work_unit tasks runs and raises an exception, causing fake_error_handler to be called.

Actual Behavior

When trying to run the second formulation, I get an AttributeError and no task is ever run:

>>> from test_celery import test
>>> test()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/asteinborn/Ramp/misc/celery-test/test_celery.py", line 68, in test
    ).on_error(f2).apply_async()
  File "/Users/asteinborn/Ramp/misc/celery-test/venv/lib/python3.10/site-packages/celery/canvas.py", line 1035, in apply_async
    return self.run(args, kwargs, app=app, **(
  File "/Users/asteinborn/Ramp/misc/celery-test/venv/lib/python3.10/site-packages/celery/canvas.py", line 1060, in run
    tasks, results_from_prepare = self.prepare_steps(
  File "/Users/asteinborn/Ramp/misc/celery-test/venv/lib/python3.10/site-packages/celery/canvas.py", line 1246, in prepare_steps
    task.link_error(errback)
  File "/Users/asteinborn/Ramp/misc/celery-test/venv/lib/python3.10/site-packages/celery/canvas.py", line 2276, in link_error
    task.link_error(errback.clone(immutable=True))
AttributeError: 'str' object has no attribute 'link_error'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions