question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Celery throwing ImproperlyConfigured error when adding new app

See original GitHub issue
  • I’m submitting a …

    • bug report
    • feature request
    • support request => Please do not submit support request here, see note at the top of this template.
  • Do you want to request a feature or report a bug? Report a bug; I swear

  • What is the current behavior? Adding a new app to my celery-enabled cookiecutter-django project results in an exception being thrown and both celerybeat and celeryworker unceremoniously exiting

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

I started a fresh Dockerized cookiecutter-django project. In the setup, I chose to use Celery. All of the containers started fine and everything just worked, until I added a bare-bones new app called reviews. The app is only 2 files, apps.py and models.py Both are dead-simple:

# apps.py
from django.apps import AppConfig
class ReviewConfig(AppConfig):
    name = 'reviews'
    verbose_name = 'Reviews'

# models.py
import uuid
from django.db import models
class Review(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

I added my app to base.py like so:

LOCAL_APPS = [
    'my_awesome_project.users.apps.UsersConfig',
    # Your stuff: custom apps go here
    'my_awesome_project.reviews.apps.ReviewConfig',
]

After doing this, both celeryworker and celerybeat throw this exception and exit:

celeryworker_1  | django.core.exceptions.ImproperlyConfigured: Cannot import 'reviews'. Check that 'my_awesome_project.reviews.apps.ReviewConfig.name' is correct.

Note that the django service still runs just fine and recognized the reviews app with no problem.

  • What is the expected behavior? The celeryworker and celerybeat services should recognize the new app and work as they did before the app was added

  • Please tell us about your environment: I’m using Docker, so I’m not sure what info to provide here

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

Here’s the docker-compose output for celerybeat:

celerybeat_1    | PostgreSQL is up - continuing...
celerybeat_1    | + rm -f ./celerybeat.pid
celerybeat_1    | + celery -A my_awesome_project.taskapp beat -l INFO
celerybeat_1    | celery beat v3.1.25 (Cipater) is starting.
myawesomeproject_celeryworker_1 exited with code 1
celerybeat_1    | Traceback (most recent call last):
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 143, in create
celerybeat_1    |     app_module = import_module(app_name)
celerybeat_1    |   File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
celerybeat_1    |     return _bootstrap._gcd_import(name[level:], package, level)
celerybeat_1    |   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
celerybeat_1    |   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
celerybeat_1    |   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
celerybeat_1    | ModuleNotFoundError: No module named 'reviews'
celerybeat_1    |
celerybeat_1    | During handling of the above exception, another exception occurred:
celerybeat_1    |
celerybeat_1    | Traceback (most recent call last):
celerybeat_1    |   File "/usr/local/bin/celery", line 11, in <module>
celerybeat_1    |     sys.exit(main())
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/__main__.py", line 30, in main
celerybeat_1    |     main()
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/bin/celery.py", line 81, in main
celerybeat_1    |     cmd.execute_from_commandline(argv)
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/bin/celery.py", line 793, in execute_from_commandline
celerybeat_1    |     super(CeleryCommand, self).execute_from_commandline(argv)))
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/bin/base.py", line 311, in execute_from_commandline
celerybeat_1    |     return self.handle_argv(self.prog_name, argv[1:])
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/bin/celery.py", line 785, in handle_argv
celerybeat_1    |     return self.execute(command, argv)
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/bin/celery.py", line 717, in execute
celerybeat_1    |     ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/bin/base.py", line 315, in run_from_argv
celerybeat_1    |     sys.argv if argv is None else argv, command)
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/bin/base.py", line 377, in handle_argv
celerybeat_1    |     return self(*args, **options)
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/bin/base.py", line 274, in __call__
celerybeat_1    |     ret = self.run(*args, **kwargs)
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/bin/beat.py", line 79, in run
celerybeat_1    |     return beat().run()
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/apps/beat.py", line 81, in run
celerybeat_1    |     self.init_loader()
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/apps/beat.py", line 121, in init_loader
celerybeat_1    |     self.app.loader.init_worker()
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/loaders/base.py", line 128, in init_worker
celerybeat_1    |     self.import_default_modules()
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/loaders/base.py", line 116, in import_default_modules
celerybeat_1    |     signals.import_modules.send(sender=self.app)
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/utils/dispatch/signal.py", line 166, in send
celerybeat_1    |     response = receiver(signal=self, sender=sender, **named)
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/fixups/django.py", line 73, in on_import_modules
celerybeat_1    |     self.worker_fixup.validate_models()
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/celery/fixups/django.py", line 158, in validate_models
celerybeat_1    |     django_setup()
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
celerybeat_1    |     apps.populate(settings.INSTALLED_APPS)
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
celerybeat_1    |     app_config = AppConfig.create(entry)
celerybeat_1    |   File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 147, in create
celerybeat_1    |     app_name, mod_path, cls_name,
celerybeat_1    | django.core.exceptions.ImproperlyConfigured: Cannot import 'reviews'. Check that 'my_awesome_project.reviews.apps.ReviewConfig.name' is correct.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

14reactions
luzfcbcommented, May 22, 2018

@radius probably the problem occurs, because the reviews app is inside the module my_awesome_project (side by side of users app and taskapp app), but the name parameter of your ReviewConfig should have included the "module_name.app_name", like :

# my_awesome_project/reviews/apps.py
from django.apps import AppConfig
class ReviewConfig(AppConfig):
    name = 'my_awesome_project.reviews'
    verbose_name = 'Reviews'

and NOT app_name like :

# my_awesome_project/reviews/apps.py
from django.apps import AppConfig
class ReviewConfig(AppConfig):
    name = 'reviews'
    verbose_name = 'Reviews'
0reactions
parliicommented, Feb 2, 2022

This was helpful to me too!! Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Celery throwing ImproperlyConfigured error when adding new ...
What is the current behavior? ... After doing this, both celeryworker and celerybeat throw this exception and exit: celeryworker_1 | django.core.
Read more >
raise ImproperlyConfigured("The SECRET_KEY setting must ...
I am trying to deploy my Django app on Heroku. Whenever I go to my app I am getting an error: 2020-09-06T20:31:59.000436+00:00 app[web.1]: ......
Read more >
Tasks — Celery 5.2.7 documentation
Tasks¶. Tasks are the building blocks of Celery applications. A task is a class that can be created out of any callable. It...
Read more >
Django: Celery import causes error while executing cron ...
Coding example for the question Django: Celery import causes error while executing cron commands-django.
Read more >
Celery Documentation - Read the Docs
If you're new to Celery you can get started by following the First ... Note: If you're getting nodedown errors after installing and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found