I am currently using Heroku CI to run my django tests:
python3 manage.py test --fail-fast
However upon running these on the heroku CI i get an infinite loop when the django system tries to render the settings:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/app/investorsuite/middleware.py", line 11, in middleware
response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 95, in response_for_exception
exc_info=sys.exc_info(),
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/log.py", line 228, in log_response
exc_info=exc_info,
File "/app/.heroku/python/lib/python3.6/logging/__init__.py", line 1337, in error
self._log(ERROR, msg, args, **kwargs)
File "/app/.heroku/python/lib/python3.6/logging/__init__.py", line 1444, in _log
self.handle(record)
File "/app/.heroku/python/lib/python3.6/logging/__init__.py", line 1454, in handle
self.callHandlers(record)
File "/app/.heroku/python/lib/python3.6/logging/__init__.py", line 1516, in callHandlers
hdlr.handle(record)
File "/app/.heroku/python/lib/python3.6/logging/__init__.py", line 865, in handle
self.emit(record)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/log.py", line 120, in emit
message = "%s\n\n%s" % (self.format(no_exc_record), reporter.get_traceback_text())
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/debug.py", line 340, in get_traceback_text
c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/debug.py", line 306, in get_traceback_data
'settings': get_safe_settings(),
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/debug.py", line 80, in get_safe_settings
settings_dict[k] = cleanse_setting(k, getattr(settings, k))
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/debug.py", line 58, in cleanse_setting
cleansed = {k: cleanse_setting(k, v) for k, v in value.items()}
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/debug.py", line 58, in <dictcomp>
cleansed = {k: cleanse_setting(k, v) for k, v in value.items()}
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/debug.py", line 58, in cleanse_setting
cleansed = {k: cleanse_setting(k, v) for k, v in value.items()}
.......
RecursionError: maximum recursion depth exceeded
and i am not really sure what the reason behind the bug is. i have looked for dictionaries that might be at fault (cleanse_setting recursively enters dictionaries) but i cannot seem to find any in my settings file:
import os
import sentry_sdk
from django.contrib.messages import constants as messages
from sentry_sdk.integrations.django import \
DjangoIntegration
from decimal import Decimal
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '********'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG_ENV = os.getenv('DEBUG_MODE', '1')
DEBUG = DEBUG_ENV.lower() == 'true' or DEBUG_ENV == '1'
SITE_NAME = os.getenv("SITE_NAME", '********')
DOMAIN = os.getenv('DOMAIN', '********')
ALLOWED_HOSTS = [
DOMAIN,
"." + DOMAIN, # subdomains
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
....
]
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = '******'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'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',
],
},
}
]
PROJECT_DIR = os.path.dirname(__file__)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
WSGI_APPLICATION = '********'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
},
'NAME': '********',
'USER': '********',
'PASSWORD':'********',
'HOST': 'localhost',
'PORT': '3306',
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/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',
},
]
##
AUTH_USER_MODEL = "accounts.User"
LOGIN_URL = "/"
LOGOUT_REDIRECT_URL = "/"
# media
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
# emailing
EMAIL_HOST = 'smtp.mailgun.org'
EMAIL_PORT = 587
EMAIL_HOST_USER = '********'
EMAIL_HOST_PASSWORD = '********'
EMAIL_USE_TLS = True
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
MANAGEMENT_FEE = Decimal("0.02")
PERFORMANCE_FEE = Decimal("0.2")
try:
from settings_local import *
except ImportError:
pass
if DEBUG and 'EMAIL_BACKEND' not in vars():
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
SENTRY_DOMAIN = '********'
# TODO make environment a bit smarter based on environment
if not DEBUG:
import socket
SENTRY_IO_NAME = os.getenv('SENTRY_IO_NAME', socket.gethostname())
sentry_sdk.init(
SENTRY_DOMAIN,
integrations=[DjangoIntegration()],
environment=SENTRY_IO_NAME
)
# Configure Django App for Heroku.
try:
import django_heroku
if os.getenv('JAWSDB_URL', '') is not '':
os.environ['DATABASE_URL'] = os.getenv('JAWSDB_URL', '')
django_heroku.settings(locals())
# following line because of https://github.com/kennethreitz/dj-database-url/issues/107
DATABASES['default']['init_command'] = "SET sql_mode='STRICT_TRANS_TABLES'"
try:
del DATABASES['default']['OPTIONS']['sslmode']
except:
pass
except ModuleNotFoundError:
print("Heroku not in use.")
utilizing Django2.2.1 and python 3.6.8
EDIT: so apparently the DATABASE value in settings is defined recursively for some reason by heroku?:
>>> settings.DATABASES['default']['TEST']['TEST']
{'NAME': '*****', 'USER': '*****', 'PASSWORD': '*****', 'HOST': '******', 'PORT': 3306, 'CONN_MAX_AGE': 600, 'OPTIONS': {}, 'ENGINE': 'django.db.backends.mysql', 'TEST': {...}, 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'TIME_ZONE': None, 'CHARSET': None, 'COLLATION': None, 'MIRROR': None}
Which doesn't really confuse me less
EDIT2: I've tried cleaning up the files and tested different things, and feel pretty lost. I don't really know where to go from here. Should i report a bug on the git repo for django_heroku? it's probably just me doing something wrong, but i don't really know where to go. i'll try creating a minimum implementation of a django app and try reproducing the bug one of the following days, worst case.