kombu utils objects py line 42 in __ get __ return obj __ dict __[ self __ name __] keyerror data

Viewed 2186

settings.py

CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Makassar'
# Other Celery settings
CELERY_BEAT_SCHEDULE = {
    'add_task': {
        'add_task': 'data_loader.tasks.add_task',
        'schedule': crontab(minute=55, hour=13),

    }
    # 'task-number-two': {
    #     'task': 'data_loader.tasks.demo',
    #     'schedule': crontab(minute=2, hour='18'),
    # }
}

celery.py ..............

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'resolution_validator.settings')

app = Celery('resolution_validator')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

tasks.py ............

from __future__ import absolute_import, unicode_literals

from celery.task import task


@task()
def add_task():
    print("hello world")
    a = 10
    return True

init.py ...............

from __future__ import absolute_import, unicode_literals

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__all__ = ['celery_app']

I am also getting the following error

"RecursionError: maximum recursion depth exceeded" with the KeyError.

I am using Django==2.0,celery==4.2.0,python==3.5.2 Not able to get the solution .

1 Answers

There is a problem with your tasks.py. You should use @shared_task decorator instead of @task decorator

from __future__ import absolute_import, unicode_literals

from celery import shared_task


@shared_task
def add_task():
    print("hello world")
    a = 10
    return True
Related