Django AppRegistryNotReady("Models aren't loaded yet.") when deploying on heroku

Feature(s) impacted

When I try to deploy my git directory on heroku, I get this error that I can’t solve

Observed behavior

I am at the point where I enter the heroku url to get the remote admin.

Unfortunately nothing happens as expected.

I check with the command heroku logs --tail what is going on.

I get this error that I can’t solve

Failure Logs

 ›   Warning: heroku update available from 7.60.1 to 7.60.2.
2022-05-03T08:37:47.692874+00:00 app[web.1]: return self.load_wsgiapp()
2022-05-03T08:37:47.692875+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-05-03T08:37:47.692875+00:00 app[web.1]: return util.import_app(self.app_uri)
2022-05-03T08:37:47.692876+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2022-05-03T08:37:47.692876+00:00 app[web.1]: mod = importlib.import_module(module)
2022-05-03T08:37:47.692876+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2022-05-03T08:37:47.692877+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-05-03T08:37:47.692877+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2022-05-03T08:37:47.692878+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2022-05-03T08:37:47.692878+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2022-05-03T08:37:47.692878+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2022-05-03T08:37:47.692879+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 843, in exec_module
2022-05-03T08:37:47.692879+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2022-05-03T08:37:47.692879+00:00 app[web.1]: File "/app/siteweb/wsgi.py", line 18, in <module>
2022-05-03T08:37:47.692880+00:00 app[web.1]: init_forest()
2022-05-03T08:37:47.692880+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django_forest/__init__.py", line 11, in init_forest
2022-05-03T08:37:47.692880+00:00 app[web.1]: Schema.build_schema()
2022-05-03T08:37:47.692881+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django_forest/utils/schema/__init__.py", line 117, in build_schema
2022-05-03T08:37:47.692881+00:00 app[web.1]: for model in Models.list():
2022-05-03T08:37:47.692881+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django_forest/utils/models.py", line 14, in list
2022-05-03T08:37:47.692882+00:00 app[web.1]: cls.models = apps.get_models(include_auto_created=True)
2022-05-03T08:37:47.692882+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/apps/registry.py", line 181, in get_models
2022-05-03T08:37:47.692882+00:00 app[web.1]: self.check_models_ready()
2022-05-03T08:37:47.692883+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/apps/registry.py", line 143, in check_models_ready
2022-05-03T08:37:47.692883+00:00 app[web.1]: raise AppRegistryNotReady("Models aren't loaded yet.")
2022-05-03T08:37:47.692883+00:00 app[web.1]: django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
2022-05-03T08:37:47.692884+00:00 app[web.1]: [2022-05-03 08:37:47 +0000] [10] [INFO] Worker exiting (pid: 10)
2022-05-03T08:37:47.830330+00:00 app[web.1]: [2022-05-03 08:37:47 +0000] [11] [ERROR] Exception in worker process
2022-05-03T08:37:47.830331+00:00 app[web.1]: Traceback (most recent call last):
2022-05-03T08:37:47.830332+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2022-05-03T08:37:47.830333+00:00 app[web.1]: worker.init_process()
2022-05-03T08:37:47.830333+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
2022-05-03T08:37:47.830333+00:00 app[web.1]: self.load_wsgi()
2022-05-03T08:37:47.830334+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2022-05-03T08:37:47.830334+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2022-05-03T08:37:47.830335+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
2022-05-03T08:37:47.830335+00:00 app[web.1]: self.callable = self.load()
2022-05-03T08:37:47.830336+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2022-05-03T08:37:47.830336+00:00 app[web.1]: return self.load_wsgiapp()
2022-05-03T08:37:47.830336+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-05-03T08:37:47.830336+00:00 app[web.1]: return util.import_app(self.app_uri)
2022-05-03T08:37:47.830337+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
2022-05-03T08:37:47.830337+00:00 app[web.1]: mod = importlib.import_module(module)
2022-05-03T08:37:47.830337+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
2022-05-03T08:37:47.830337+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-05-03T08:37:47.830337+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2022-05-03T08:37:47.830338+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2022-05-03T08:37:47.830338+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2022-05-03T08:37:47.830338+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2022-05-03T08:37:47.830338+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 843, in exec_module
2022-05-03T08:37:47.830338+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2022-05-03T08:37:47.830339+00:00 app[web.1]: File "/app/siteweb/wsgi.py", line 18, in <module>
2022-05-03T08:37:47.830339+00:00 app[web.1]: init_forest()
2022-05-03T08:37:47.830339+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django_forest/__init__.py", line 11, in init_forest
2022-05-03T08:37:47.830339+00:00 app[web.1]: Schema.build_schema()
2022-05-03T08:37:47.830340+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django_forest/utils/schema/__init__.py", line 117, in build_schema
2022-05-03T08:37:47.830340+00:00 app[web.1]: for model in Models.list():
2022-05-03T08:37:47.830340+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django_forest/utils/models.py", line 14, in list
2022-05-03T08:37:47.830340+00:00 app[web.1]: cls.models = apps.get_models(include_auto_created=True)
2022-05-03T08:37:47.830340+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/apps/registry.py", line 181, in get_models
2022-05-03T08:37:47.830340+00:00 app[web.1]: self.check_models_ready()
2022-05-03T08:37:47.830340+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/apps/registry.py", line 143, in check_models_ready
2022-05-03T08:37:47.830341+00:00 app[web.1]: raise AppRegistryNotReady("Models aren't loaded yet.")
2022-05-03T08:37:47.830341+00:00 app[web.1]: django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
2022-05-03T08:37:47.830474+00:00 app[web.1]: [2022-05-03 08:37:47 +0000] [11] [INFO] Worker exiting (pid: 11)
2022-05-03T08:37:47.931002+00:00 app[web.1]: Traceback (most recent call last):
2022-05-03T08:37:47.931009+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 209, in run
2022-05-03T08:37:47.931247+00:00 app[web.1]: self.sleep()
2022-05-03T08:37:47.931251+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 357, in sleep
2022-05-03T08:37:47.931387+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
2022-05-03T08:37:47.931396+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2022-05-03T08:37:47.931494+00:00 app[web.1]: self.reap_workers()
2022-05-03T08:37:47.931502+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2022-05-03T08:37:47.931639+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2022-05-03T08:37:47.931698+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2022-05-03T08:37:47.931718+00:00 app[web.1]: 
2022-05-03T08:37:47.931718+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2022-05-03T08:37:47.931718+00:00 app[web.1]: 
2022-05-03T08:37:47.931719+00:00 app[web.1]: Traceback (most recent call last):
2022-05-03T08:37:47.931719+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
2022-05-03T08:37:47.931780+00:00 app[web.1]: sys.exit(run())
2022-05-03T08:37:47.931788+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
2022-05-03T08:37:47.931863+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2022-05-03T08:37:47.931879+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 231, in run
2022-05-03T08:37:47.931961+00:00 app[web.1]: super().run()
2022-05-03T08:37:47.931963+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/app/base.py", line 72, in run
2022-05-03T08:37:47.932043+00:00 app[web.1]: Arbiter(self).run()
2022-05-03T08:37:47.932045+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 229, in run
2022-05-03T08:37:47.932126+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2022-05-03T08:37:47.932128+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 342, in halt
2022-05-03T08:37:47.932236+00:00 app[web.1]: self.stop()
2022-05-03T08:37:47.932245+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 393, in stop
2022-05-03T08:37:47.932378+00:00 app[web.1]: time.sleep(0.1)
2022-05-03T08:37:47.932386+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2022-05-03T08:37:47.932484+00:00 app[web.1]: self.reap_workers()
2022-05-03T08:37:47.932492+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2022-05-03T08:37:47.932622+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2022-05-03T08:37:47.932668+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2022-05-03T08:37:48.092256+00:00 heroku[web.1]: Process exited with status 1
2022-05-03T08:37:48.174465+00:00 heroku[web.1]: State changed from up to crashed

Context

settings.py

"""
Django settings for siteweb project.

Generated by 'django-admin startproject' using Django 4.0.4.

For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-lz1xcty^#$tt^0r=zqv-g&08z7p@x(pqzw@_o=(&uohbzan0$4'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['https://forestadminmika.herokuapp.com']


FOREST = {
    'FOREST_URL': 'https://api.forestadmin.com',
    'APPLICATION_URL': 'https://forestadminmika.herokuapp.com' ,
    'FOREST_ENV_SECRET': ' dad33e1555c9e06fc4b6eec7647a8943548cafce1afd0e70871bb25081355130',
    'FOREST_AUTH_SECRET': '9ccceeef3e97f9c583fe95971242f048e246f768da844ca2 '
}
APPEND_SLASH=False

# Application definition

INSTALLED_APPS = [
    'django_forest',    
    'django.contrib.admin',
    'corsheaders',
    'producthunt.apps.ProducthuntConfig',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_extensions',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    "django.middleware.csrf.CsrfViewMiddleware",
    "corsheaders.middleware.CorsPostCsrfMiddleware",    
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True

ROOT_URLCONF = 'siteweb.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'siteweb.wsgi.application'

# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'd3s831ci7ce7vf',
        'USER': 'user',
        'PASSWORD': 'pass',
        'HOST': 'ec2-176-34-211-0.eu-west-1.compute.amazonaws.com',
        'PORT': '5432',

    }

}


# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

wsgi.py


"""
WSGI config for siteweb project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""

import os
from django.conf import settings

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'siteweb.settings')

from django.core.wsgi import get_wsgi_application
print(settings.FOREST)
from django_forest import init_forest
init_forest() 
application = get_wsgi_application()

urls.py

from django.contrib import admin
from django.conf.urls import include
from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
    path('forest', include('django_forest.urls')),    
]

Procfile

release: python manage.py migrate --no-input
web: gunicorn siteweb.wsgi

Tree

siteweb
├── db.sqlite3
├── .forestadmin-schema.json
├── .git
│   ├── branches
│   ├── COMMIT_EDITMSG
│   ├── config
│   ├── description
│   ├── HEAD
│   ├── hooks
│   │   ├── applypatch-msg.sample
│   │   ├── commit-msg.sample
│   │   ├── fsmonitor-watchman.sample
│   │   ├── post-update.sample
│   │   ├── pre-applypatch.sample
│   │   ├── pre-commit.sample
│   │   ├── pre-merge-commit.sample
│   │   ├── prepare-commit-msg.sample
│   │   ├── pre-push.sample
│   │   ├── pre-rebase.sample
│   │   ├── pre-receive.sample
│   │   ├── push-to-checkout.sample
│   │   └── update.sample
│   ├── index
│   ├── info
│   │   └── exclude
│   ├── logs
│   │   ├── HEAD
│   │   └── refs
│   │       ├── heads
│   │       │   └── master
│   │       └── remotes
│   │           └── heroku
│   │               └── master
├── manage.py
├── Procfile
├── producthunt
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── 0002_alter_producthuntitem_author_name_and_more.py
│   │   ├── 0003_alter_producthuntitem_author_name_and_more.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   │       ├── 0001_initial.cpython-38.pyc
│   │       ├── 0002_alter_producthuntitem_author_name_and_more.cpython-38.pyc
│   │       ├── 0003_alter_producthuntitem_author_name_and_more.cpython-38.pyc
│   │       └── __init__.cpython-38.pyc
│   ├── models.py
│   ├── __pycache__
│   │   ├── admin.cpython-38.pyc
│   │   ├── apps.cpython-38.pyc
│   │   ├── __init__.cpython-38.pyc
│   │   └── models.cpython-38.pyc
│   ├── tests.py
│   └── views.py
├── requirements.txt
├── runtime.txt
├── scripts
│   ├── __init__.py
│   ├── load_producthunt.py
│   ├── parse_items.py
│   ├── proxies_file.py
│   ├── __pycache__
│   │   ├── __init__.cpython-38.pyc
│   │   ├── load_producthunt.cpython-38.pyc
│   │   ├── parse_items.cpython-38.pyc
│   │   ├── proxies_file.cpython-38.pyc
│   │   └── user_agents_file.cpython-38.pyc
│   └── user_agents_file.py
├── siteweb
│   ├── asgi.py
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-38.pyc
│   │   ├── settings.cpython-38.pyc
│   │   ├── urls.cpython-38.pyc
│   │   └── wsgi.cpython-38.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── static
│   ├── admin
│   │   ├── css
│   │   │   ├── autocomplete.css
│   │   │   ├── base.css
│   │   │   ├── changelists.css
│   │   │   ├── dashboard.css
│   │   │   ├── fonts.css
│   │   │   ├── forms.css
│   │   │   ├── login.css
│   │   │   ├── nav_sidebar.css
│   │   │   ├── responsive.css
│   │   │   ├── responsive_rtl.css
│   │   │   ├── rtl.css
│   │   │   ├── vendor
│   │   │   │   └── select2
│   │   │   │       ├── LICENSE-SELECT2.md
│   │   │   │       ├── select2.css
│   │   │   │       └── select2.min.css
│   │   │   └── widgets.css
│   │   ├── fonts
│   │   │   ├── LICENSE.txt
│   │   │   ├── README.txt
│   │   │   ├── Roboto-Bold-webfont.woff
│   │   │   ├── Roboto-Light-webfont.woff
│   │   │   └── Roboto-Regular-webfont.woff
│   │   ├── img
│   │   │   ├── calendar-icons.svg
│   │   │   ├── gis
│   │   │   │   ├── move_vertex_off.svg
│   │   │   │   └── move_vertex_on.svg
│   │   │   ├── icon-addlink.svg
│   │   │   ├── icon-alert.svg
│   │   │   ├── icon-calendar.svg
│   │   │   ├── icon-changelink.svg
│   │   │   ├── icon-clock.svg
│   │   │   ├── icon-deletelink.svg
│   │   │   ├── icon-no.svg
│   │   │   ├── icon-unknown-alt.svg
│   │   │   ├── icon-unknown.svg
│   │   │   ├── icon-viewlink.svg
│   │   │   ├── icon-yes.svg
│   │   │   ├── inline-delete.svg
│   │   │   ├── LICENSE
│   │   │   ├── README.txt
│   │   │   ├── search.svg
│   │   │   ├── selector-icons.svg
│   │   │   ├── sorting-icons.svg
│   │   │   ├── tooltag-add.svg
│   │   │   └── tooltag-arrowright.svg
│   │   └── js
│   │       ├── actions.js
│   │       ├── admin
│   │       │   ├── DateTimeShortcuts.js
│   │       │   └── RelatedObjectLookups.js
│   │       ├── autocomplete.js
│   │       ├── calendar.js
│   │       ├── cancel.js
│   │       ├── change_form.js
│   │       ├── collapse.js
│   │       ├── core.js
│   │       ├── inlines.js
│   │       ├── jquery.init.js
│   │       ├── nav_sidebar.js
│   │       ├── popup_response.js
│   │       ├── prepopulate_init.js
│   │       ├── prepopulate.js
│   │       ├── SelectBox.js
│   │       ├── SelectFilter2.js
│   │       ├── urlify.js
│   │       └── vendor
│   │           ├── jquery
│   │           │   ├── jquery.js
│   │           │   ├── jquery.min.js
│   │           │   └── LICENSE.txt
│   │           ├── select2
│   │           │   ├── i18n
│   │           │   │   ├── af.js
│   │           │   │   ├── ar.js
│   │           │   │   ├── az.js
│   │           │   │   ├── bg.js
│   │           │   │   ├── bn.js
│   │           │   │   ├── bs.js
│   │           │   │   ├── ca.js
│   │           │   │   ├── cs.js
│   │           │   │   ├── da.js
│   │           │   │   ├── de.js
│   │           │   │   ├── dsb.js
│   │           │   │   ├── el.js
│   │           │   │   ├── en.js
│   │           │   │   ├── es.js
│   │           │   │   ├── et.js
│   │           │   │   ├── eu.js
│   │           │   │   ├── fa.js
│   │           │   │   ├── fi.js
│   │           │   │   ├── fr.js
│   │           │   ├── LICENSE.md
│   │           │   ├── select2.full.js
│   │           │   └── select2.full.min.js
│   │           └── xregexp
│   │               ├── LICENSE.txt
│   │               ├── xregexp.js
│   │               └── xregexp.min.js
│   └── django_extensions
│       ├── css
│       │   └── jquery.autocomplete.css
│       ├── img
│       │   └── indicator.gif
│       └── js
│           ├── jquery.ajaxQueue.js
│           ├── jquery.autocomplete.js
│           └── jquery.bgiframe.js
└── tree.txt

202 directories, 445 files

I am working on python 3.8 (runtime.txt)

Hello @MikaelMonjour,

Do you try to run your project with gunicorn on your own computer before to run it on Heroku ?
I have a similar config that run well on Heroku.

I used python3 manage.py runserver locally.

But after testing locally it cameback with the same error

$ gunicorn siteweb.wsgi

[2022-05-03 14:39:01 +0200] [24195] [INFO] Starting gunicorn 20.1.0
[2022-05-03 14:39:01 +0200] [24195] [INFO] Listening at: http://127.0.0.1:8000 (24195)
[2022-05-03 14:39:01 +0200] [24195] [INFO] Using worker: sync
[2022-05-03 14:39:01 +0200] [24197] [INFO] Booting worker with pid: 24197
{'FOREST_URL': 'https://api.forestadmin.com', 'APPLICATION_URL': 'https://forestadminmika.herokuapp.com', 'FOREST_ENV_SECRET': ' dad33e1555c9e06fc4b6eec7647a8943548cafce1afd0e70871bb25081355130', 'FOREST_AUTH_SECRET': '9ccceeef3e97f9c583fe95971242f048e246f768da844ca2'}
[2022-05-03 12:39:02 +0000] [24197] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/gunicorn/workers/base.py", line 134, in init_process
    self.load_wsgi()
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
    return self.load_wsgiapp()
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/gunicorn/util.py", line 359, in import_app
    mod = importlib.import_module(module)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/eduba/scripts/envoi forest/django/siteweb/siteweb/wsgi.py", line 18, in <module>
    init_forest()
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/django_forest/__init__.py", line 11, in init_forest
    Schema.build_schema()
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/django_forest/utils/schema/__init__.py", line 117, in build_schema
    for model in Models.list():
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/django_forest/utils/models.py", line 14, in list
    cls.models = apps.get_models(include_auto_created=True)
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/django/apps/registry.py", line 181, in get_models
    self.check_models_ready()
  File "/home/eduba/scripts/envoi forest/django/venv/lib/python3.8/site-packages/django/apps/registry.py", line 143, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
[2022-05-03 12:39:02 +0000] [24197] [INFO] Worker exiting (pid: 24197)
[2022-05-03 14:39:02 +0200] [24195] [INFO] Shutting down: Master
[2022-05-03 14:39:02 +0200] [24195] [INFO] Reason: Worker failed to boot

Hi @MikaelMonjour,

Ok, the init workflow seems to work with asgi but not with wsgi.
To fix your issue, move the init_forest call below the get_wsgi_application call.

#init_forest() to remove

application = get_wsgi_application()
init_forest()

seems ok locally ?

I am trying a push on heroku

[2022-05-03 15:32:19 +0200] [28795] [INFO] Starting gunicorn 20.0.0
[2022-05-03 15:32:19 +0200] [28795] [INFO] Listening at: http://127.0.0.1:8000 (28795)
[2022-05-03 15:32:19 +0200] [28795] [INFO] Using worker: sync
[2022-05-03 15:32:19 +0200] [28798] [INFO] Booting worker with pid: 28798
{'FOREST_URL': 'https://api.forestadmin.com', 'APPLICATION_URL': 'https://forestadminmika.herokuapp.com', 'FOREST_ENV_SECRET': ' ', 'FOREST_AUTH_SECRET': ''}
Cannot send the apimap to Forest. Are you online?

You need to set the FOREST_ENV_SECRET and the FOREST_AUTH_SECRET in you heroku Environment variables.

The local connection does not work anymore :smiling_face_with_tear:
I do not get anything on log file :smiling_face_with_tear:

What did you change ? If you’re changed only the wsgi file, there are no reasons to break the local environment.
What’s happened on server start ?

I restart everything from scratch, it seems to work but url not responding …

heroku logs -tail

2022-05-03T15:37:03.921013+00:00 heroku[web.1]: Restarting
2022-05-03T15:37:03.933325+00:00 heroku[web.1]: State changed from up to starting
2022-05-03T15:37:04.000000+00:00 app[api]: Build succeeded
2022-05-03T15:37:04.149476+00:00 app[web.1]: 10.1.15.214 - - [03/May/2022:15:37:04 +0000] "OPTIONS /forest HTTP/1.1" 200 0 "https://app.forestadmin.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0"
2022-05-03T15:37:04.149606+00:00 heroku[router]: at=info method=OPTIONS path="/forest" host=forestadminmika2.herokuapp.com request_id=f9272c54-c3f0-4a0f-aaf5-324e09789817 fwd="78.198.213.112" dyno=web.1 connect=0ms service=1ms status=200 bytes=306 protocol=https
2022-05-03T15:37:04.817824+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-05-03T15:37:05.242117+00:00 app[web.1]: [2022-05-03 15:37:05 +0000] [10] [INFO] Worker exiting (pid: 10)
2022-05-03T15:37:05.242133+00:00 app[web.1]: [2022-05-03 15:37:05 +0000] [4] [INFO] Handling signal: term
2022-05-03T15:37:05.242215+00:00 app[web.1]: [2022-05-03 15:37:05 +0000] [11] [INFO] Worker exiting (pid: 11)
2022-05-03T15:37:05.250698+00:00 app[web.1]: [2022-05-03 15:37:05 +0000] [4] [WARNING] Worker with pid 11 was terminated due to signal 15
2022-05-03T15:37:05.251644+00:00 app[web.1]: [2022-05-03 15:37:05 +0000] [4] [WARNING] Worker with pid 10 was terminated due to signal 15
2022-05-03T15:37:05.343079+00:00 app[web.1]: [2022-05-03 15:37:05 +0000] [4] [INFO] Shutting down: Master
2022-05-03T15:37:05.500572+00:00 heroku[web.1]: Process exited with status 0
2022-05-03T15:37:12.591299+00:00 heroku[web.1]: Starting process with command `gunicorn lesiteweb.wsgi`
2022-05-03T15:37:15.657958+00:00 app[web.1]: {'FOREST_URL': 'https://api.forestadmin.com', 'APPLICATION_URL': 'https://forestadminmika2.herokuapp.com', 'FOREST_ENV_SECRET': 'XXXXX', 'FOREST_AUTH_SECRET': 'XXXXX'}
2022-05-03T15:37:16.418136+00:00 app[web.1]: /app/.heroku/python/lib/python3.8/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'api.forestadmin.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
2022-05-03T15:37:16.418157+00:00 app[web.1]: warnings.warn(
2022-05-03T15:37:16.482497+00:00 app[web.1]: /app/.heroku/python/lib/python3.8/site-packages/urllib3/connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'api.forestadmin.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
2022-05-03T15:37:16.482499+00:00 app[web.1]: warnings.warn(
2022-05-03T15:37:15.335175+00:00 app[web.1]: [2022-05-03 15:37:15 +0000] [4] [INFO] Starting gunicorn 20.1.0
2022-05-03T15:37:15.335793+00:00 app[web.1]: [2022-05-03 15:37:15 +0000] [4] [INFO] Listening at: http://0.0.0.0:31271 (4)
2022-05-03T15:37:15.335875+00:00 app[web.1]: [2022-05-03 15:37:15 +0000] [4] [INFO] Using worker: sync
2022-05-03T15:37:15.346759+00:00 app[web.1]: [2022-05-03 15:37:15 +0000] [10] [INFO] Booting worker with pid: 10
2022-05-03T15:37:15.451296+00:00 app[web.1]: [2022-05-03 15:37:15 +0000] [11] [INFO] Booting worker with pid: 11
2022-05-03T15:37:15.580610+00:00 app[web.1]: {'FOREST_URL': 'https://api.forestadmin.com', 'APPLICATION_URL': 'https://forestadminmika2.herokuapp.com', 'FOREST_ENV_SECRET': 'XXXXX', 'FOREST_AUTH_SECRET': 'XXXXX'}
2022-05-03T15:37:15.860593+00:00 heroku[web.1]: State changed from starting to up
2022-05-03T15:37:20.619161+00:00 app[web.1]: 10.1.15.214 - - [03/May/2022:15:37:20 +0000] "OPTIONS /forest HTTP/1.1" 200 0 "https://app.forestadmin.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0"
2022-05-03T15:37:20.619333+00:00 heroku[router]: at=info method=OPTIONS path="/forest" host=forestadminmika2.herokuapp.com request_id=dff1c6d6-9ed0-4c96-b6a3-2d2f1090cd9e fwd="78.198.213.112" dyno=web.1 connect=0ms service=4429ms status=200 bytes=306 protocol=https
2022-05-03T15:37:25.232596+00:00 heroku[router]: at=info method=OPTIONS path="/forest" host=forestadminmika2.herokuapp.com request_id=f26d67d4-1c6e-4a24-b42a-fe094716955e fwd="78.198.213.112" dyno=web.1 connect=0ms service=1589ms status=200 bytes=306 protocol=https
2022-05-03T15:37:25.232549+00:00 app[web.1]: 10.1.15.214 - - [03/May/2022:15:37:25 +0000] "OPTIONS /forest HTTP/1.1" 200 0 "https://app.forestadmin.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0"
2022-05-03T15:37:28.263172+00:00 heroku[router]: at=info method=OPTIONS path="/forest" host=forestadminmika2.herokuapp.com request_id=c5c0d5aa-9a29-41ba-9717-7dee4f8b191a fwd="78.198.213.112" dyno=web.1 connect=0ms service=6ms status=200 bytes=306 protocol=https

Hi @MikaelMonjour, I edited your last message and removed the picture you shared as you should not share your FOREST_ENV_SECRET to anybody.

Hi @MikaelMonjour ,

Could you share me the request sent by your browser.

Thanks

Hy matthv, as it’s a dummy application, I wasn’t too careful. I thank you :grinning:

1 Like

I finally succeeded in adding the admin horns and forest in allowed hosts

"""
Django settings for lesiteweb project.

Generated by 'django-admin startproject' using Django 4.0.4.

For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'duke#'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['forestadminmika2.herokuapp.com', 'app.forestadmin.com']




FOREST = {
    'FOREST_URL': 'https://api.forestadmin.com',
    'APPLICATION_URL': 'https://forestadminmika2.herokuapp.com',
    'FOREST_ENV_SECRET': '',
    'FOREST_AUTH_SECRET': ''
}
APPEND_SLASH=False



# Application definition

INSTALLED_APPS = [
    'django_forest',
    'django.contrib.admin',
    'corsheaders',    
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'producthunt.apps.ProducthuntConfig'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    "corsheaders.middleware.CorsMiddleware",
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]


CORS_ALLOWED_ORIGINS = [
    "https://app.forestadmin.com",
]

ROOT_URLCONF = 'lesiteweb.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'lesiteweb.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases


DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': '',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '5432',

    }

}


# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

Hi @MikaelMonjour,

Nice to see your project works!

You should removed app.forestadmin.com from the ALLOWED_HOSTS settings. As explained in the doc this variable is used to set the domain(s) that serve the django project.