1

I am using django celery(4.2) and I will add some task from my django view, also I want to get the task result async in a separate process, but when I try to get the result, I got some errors.

My full steps is as following:

  1. django celery config:

proj/settings/celery.py

import os
from celery import Celery
from django.conf import settings

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Nuwa.settings.development')

app = Celery('Nuwa')

app.config_from_object('django.conf:settings', namespace='CELERY')

app.autodiscover_tasks()

proj/settings.py

CELERY_BROKER_URL = f'redis://{REDIS["HOST"]}:{REDIS["PORT"]}'
CELERY_RESULT_BACKEND = f'redis://{REDIS["HOST"]}:{REDIS["PORT"]}'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'

proj/settings/init.py

from .celery import app as celery_app

__all__ = ('celery_app', )
  1. call celery task in one django view:
result = port_scan.delay(target)
redis_conn.sadd(celery_task_set_key, result.task_id)

in this step, I store the task_id in redis set for future use.

  1. get the task result
redis_conn = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
celery_tasks = redis_conn.smembers('celery-tasks')


for task_id in celery_tasks:
    print(task_id)
    celery_result = AsyncResult(task_id)
    print(celery_result.state)

when I try to get the result, it have error:

AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'

I try some solutions by search google and so, it doesn't work.

tdycss
  • 139
  • 2
  • 13
  • Even though it's "just a string" in the error - `'DisabledBackend'` sounds - disabled? Might also be a duplicate - see https://stackoverflow.com/questions/24309035/celery-result-backend-disabledbackend-object-has-no-attribute-get-task-meta-fo and https://stackoverflow.com/questions/23215311/celery-with-rabbitmq-attributeerror-disabledbackend-object-has-no-attribute (even though this uses Rabbit, I think this is more about Celery config then the different backends) – Risadinha Jan 15 '19 at 19:05
  • @Risadinha I tried all the solution you said, but it did't work – tdycss Jan 16 '19 at 02:40

1 Answers1

0

I had same issue when we upgraded from Celery 3.x to 4.x. Tried various solutions but the simplest is just to use the set_default. So, in celery.py, need to add this:

app.set_default()

This makes sure that calls to AsyncResult(task_id) will use the fully configured/bootstrapped version of Celery app (i.e. uses your set CELERY_RESULT_BACKEND), instead of the original/default version (i.e. uses the DisabledBackend).

Ranel Padon
  • 525
  • 6
  • 13