We are experiencing a critical startup failure caused by the reviewboard.admin.middleware module importing models at the module level, which is incompatible with Django 1.9+ (and especially Django 3.x/4.x+). This pattern causes Django’s application registry to not be ready at the point of import, leading to AppRegistryNotReady errors.
Error Details
On startup, we receive the following traceback:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.11/site-packages/django/core/handlers/wsgi.py", line 127, in __init__
self.load_middleware()
File "/app/.heroku/python/lib/python3.11/site-packages/django/core/handlers/base.py", line 40, in load_middleware
middleware = import_string(middleware_path)
File "/app/.heroku/python/lib/python3.11/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/app/.heroku/python/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/app/.heroku/python/lib/python3.11/site-packages/reviewboard/admin/middleware.py", line 4, in <module>
from djblets.siteconfig.models import SiteConfiguration
File "/app/.heroku/python/lib/python3.11/site-packages/djblets/siteconfig/models.py", line 7, in <module>
from django.contrib.sites.models import Site
File "/app/.heroku/python/lib/python3.11/site-packages/django/contrib/sites/models.py", line 78, in <module>
class Site(models.Model):
File "/app/.heroku/python/lib/python3.11/site-packages/django/db/models/base.py", line 108, in __new__
app_config = apps.get_containing_app_config(module)
File "/app/.heroku/python/lib/python3.11/site-packages/django/apps/registry.py", line 136, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
This is triggered by the following import in reviewboard/admin/middleware.py:
from djblets.siteconfig.models import SiteConfiguration
which executes at the module level as soon as Django attempts to import middleware classes from MIDDLEWARE in settings.py.
My versions:
- Django: 3.2.x
- Review Board: 5.0.7
- Djblets:3.3
- Python: 3.11
- Deployment: Heroku
Steps to Reproduce
- Use Django 2.x or newer with Review Board.
- Add 'reviewboard.admin.middleware.ReviewBoardMiddleware' to your MIDDLEWARE in Django settings.
- Attempt to start any Django process (runserver, uWSGI, etc.)
- Observe AppRegistryNotReady exception on startup.