Skip to content

Results not stored when task_ignore_result=True, but ignore_result=False set on apply_async #9654

Description

@alistairwatts

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).
  • I have tried to reproduce the issue with pytest-celery and added the reproduction script below.

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

  • None

Possible Duplicates

  • None

Environment & Settings

Celery version: 5.5.0 (immunity)

celery report Output:

Steps to Reproduce

Required Dependencies

  • Minimal Python Version: Unknown
  • Minimal Celery Version: Unknown
  • Minimal Kombu Version: Unknown
  • Minimal Broker Version: Unknown
  • Minimal Result Backend Version: Unknown
  • Minimal OS and/or Kernel Version: Unknown
  • Minimal Broker Client Version: Unknown
  • Minimal Result Backend Client Version: Unknown

Python Packages

pip freeze Output:

amqp==5.3.1
billiard==4.2.1
celery==5.5.0
click==8.1.8
click-didyoumean==0.3.1
click-plugins==1.1.1
click-repl==0.3.0
kombu==5.5.2
prompt_toolkit==3.0.50
python-dateutil==2.9.0.post0
six==1.17.0
typing_extensions==4.12.2
tzdata==2025.2
vine==5.1.0
wcwidth==0.2.13

Other Dependencies

Details

N/A

Minimally Reproducible Test Case

Details

# celeryconfig.py

task_ignore_result = True

result_backend = 'file://./'
broker_url = 'amqp://localhost'
imports = 'my_app.tasks'
task_default_queue = 'my_app_queue'
# myapp/tasks.py

from . import app

@app.task()
def test_1():
    return 1

@app.task(ignore_result=False)
def test_2():
    return 2

@app.task(ignore_result=True)
def test_3():
    return 3
# my_app/__init__.py

import celery

app = celery.Celery('app')
app.config_from_object('celeryconfig')
# tests.py
import celery
import celeryconfig
from my_app.tasks import test_1, test_2, test_3

assert celeryconfig.task_ignore_result is True

def run_test(func, kwargs, *, ready_expected, task_expected):
    print(func.__name__, kwargs)
    task = func.apply_async(**kwargs)
    try:
        task_result = task.get(timeout=1)
    except celery.exceptions.TimeoutError:
        task_result = 'TIMEOUT'
        print('  TIMEOUT')
    ready_result = task.ready()
    if ready_expected == ready_result:
        print('  PASS ', end='')
    else:
        print('  FAIL ', end='')
    print('Ready expected %r, got %r' % (ready_expected, ready_result))
    if task_expected == task_result:
        print('  PASS ', end='')
    else:
        print('  FAIL ', end='')
    print('Result expected %r, got %r' % (task_expected, task_result))
    try:
        task.forget()
    except FileNotFoundError:
        pass
    print()

if __name__ == '__main__':
    print()

    run_test(test_1, dict(),                    ready_expected=False, task_expected=None)
    run_test(test_2, dict(),                    ready_expected=True,  task_expected=1   )
    # The following test fails.
    run_test(test_3, dict(),                    ready_expected=False, task_expected=None)
    run_test(test_1, dict(ignore_result=False), ready_expected=True,  task_expected=1   )
    run_test(test_2, dict(ignore_result=False), ready_expected=True,  task_expected=2   )
    # The following test fails.
    run_test(test_3, dict(ignore_result=False), ready_expected=True,  task_expected=3   )
    run_test(test_1, dict(ignore_result=True),  ready_expected=False, task_expected=None)
    run_test(test_2, dict(ignore_result=True),  ready_expected=False, task_expected=None)
    run_test(test_3, dict(ignore_result=True),  ready_expected=False, task_expected=None)

Expected Behavior

I expect that when a task is called with apply_async(ignore_result=False) I expect to be able to .get() the result regardless of whether task_ignore_result = True in celeryconfig.py or ignore_result is set on the task.

Actual Behavior

Task results are not available when apply_async(ignore_result=False) and task_ignore_result = True in celeryconfig.py

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions