cosmic-ray: Exceptions in worker with Django (AppRegistryNotReady)

Workers crash when run on a Django project, which uses pytest-django:

% cosmic-ray worker proj.app.permissions mutate_comparison_operator 0 pytest -- proj/app/tests/test_utils.py

Causes:

Traceback (most recent call last):
  File "…/Vcs/cosmic-ray/cosmic_ray/worker.py", line 71, in worker
    module = importlib.import_module(module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "…/project/cosmic-ray/project/app/permissions.py", line 6, in <module>
    from .models import ClientApp
  File "…/project/cosmic-ray/project/app/models.py", line 16, in <module>
    from django.contrib.auth.models import (
  File "…/project/cosmic-ray/.venv/lib/python3.6/site-packages/django/contrib/auth/models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "…/project/cosmic-ray/.venv/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "…/project/cosmic-ray/.venv/lib/python3.6/site-packages/django/db/models/base.py", line 110, in __new__
    app_config = apps.get_containing_app_config(module)
  File "…/project/cosmic-ray/.venv/lib/python3.6/site-packages/django/apps/registry.py", line 247, in get_containing_app_config
    self.check_apps_ready()
  File "…/project/cosmic-ray/.venv/lib/python3.6/site-packages/django/apps/registry.py", line 125, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")

This is after I added the following to cosmic_ray.worker.worker() already (at the top of the with preserve_modules(): context manager), to cope with setting up django-configurations (which installs its own import hook):

from configurations import importer
importer.install(check_options=True)

But even in case it would work, it seems to be a huge overhead to setup Django for every mutation?!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

Thanks for your answer. I tested your branch, but it was really far from CR 3.1.0, and it failed to init. I will nevertheless give another try and keep you informed. I’ll also check for a simple project to reproduce this issue: for sure this will help both of us.