Celery autodiscover_tasks not working for all Django 1.7 apps

celery, django, python

Solution

This is discussed in a number of Celery issues, such as #2596 and #2597.

If you are using Celery 3.x, the fix is to use:

from django.apps import apps
app.autodiscover_tasks(lambda: [n.name for n in apps.get_app_configs()])

As mentioned in #3341, if you are using Celery 4.x (soon to be released) you can use:

app.autodiscover_tasks()

Problem

I have a Django 1.7 project with Celery 3.1. All the apps in my Django project work with the new AppConfig. The problem is that not all the tasks are found with `autodiscover_tasks`: ``` app.autodiscover_tasks(settings.INSTALLED_APPS) ``` If i use autodiscover_tasks like this it wil work: ``` app.autodiscover_tasks(settings.INSTALLED_APPS + ('apps.core','apps.sales')) ``` The tasks defined in websites are found but the tasks in core and sales are not. All have the same layout with `apps.py` and `tasks.py`. The project folder structure is: ``` apps core apps.py tasks.py dashboard apps.py sales apps.py tasks.py websites apps.py tasks.py ``` The class definitions are as follows: ``` class WebsitesConfig(AppConfig): name = 'apps.websites' verbose_name = 'Websites' class SalesConfig(AppConfig): name = 'apps.sales' verbose_name = 'Sales' ```

Original source