'Celery with SQLite: AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'

I want to study the celery project, but I don't know where I make a mistake. the 'tasks.py' file:

# -*- coding: utf-8 -*-
from celery import Celery

app = Celery('tasks', broker='sqla+sqlite:///celerydb.sqlite')
app.conf.update(
    CELERY_RESULT_BACKEND = 'db+sqlite:///results.sqlite',
#   CELERY_RESULT_BACKEND = 'redis://localhost/0',
#   CELERY_RESULT_BACKEND = 'amqp',
#   CELERY_RESULT_BACKEND = 'mongodb://127.0.0.1:27017/',
    CELERY_TASK_SERIALIZER = 'json',
    CELERY_IGNORE_RESULT = False,
    )

@app.task(trail=True)
def add(x, y):
    return x + y

@app.task(trail=True)
def mul(x, y):
    return x * y

@app.task(trail=True)
def xsum(numbers):
    return sum(numbers)

Then I run celery service like this:

celery -A tasks worker --loglevel=info  

it works well. then I use ipython to run flow scripts:

In [127]: result = add.delay(3,5)
In [128]: result.result

error like this:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-128-a030fb181312> in <module>()
----> 1 result.result

/home/xingming/pyvirt/local/lib/python2.7/site-packages/celery/result.pyc in result(self)
    350         If the task raised an exception, this will be the exception
    351         instance."""
--> 352         return self._get_task_meta()['result']
    353     info = result
    354 

/home/xingming/pyvirt/local/lib/python2.7/site-packages/celery/result.pyc in _get_task_meta(self)
    326     def _get_task_meta(self):
    327         if self._cache is None:
--> 328             meta = self.backend.get_task_meta(self.id)
    329             if meta:
    330                 state = meta['status']

/home/xingming/pyvirt/local/lib/python2.7/site-packages/celery/backends/base.pyc in get_task_meta(self, task_id, cache)
    292                 pass
    293 
--> 294         meta = self._get_task_meta_for(task_id)
    295         if cache and meta.get('status') == states.SUCCESS:
    296             self._cache[task_id] = meta

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

but the celery service work well:

[2014-06-04 11:17:31,656: INFO/MainProcess] Received task: tasks.add[11baa65f-4e18-44b1-80e4-9e81626ca42a]
[2014-06-04 11:17:31,658: INFO/MainProcess] Task tasks.add[11baa65f-4e18-44b1-80e4-9e81626ca42a] succeeded in 0.00117350020446s: 8

what's wrong with this?

thanks for your help!



Solution 1:[1]

You're not making a mistake. The Celery docs explain this fully: by default, the backend to store the task result is not enabled, so you can't use any of the functions that use it. If you want to do so, you need to follow the docs to configure a backend.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eric B.