Warn about top-level settings

This commit is contained in:
Klaas van Schelven
2025-01-24 11:40:13 +01:00
parent c6adfd7511
commit cf23ba707e
2 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
from django.core.checks import Warning, register
from django.conf import settings
from bugsink.app_settings import get_settings
@register("bsmain")
def check_no_nested_settings_in_unnested_form(app_configs, **kwargs):
errors = []
for key in get_settings().keys():
if hasattr(settings, key):
errors.append(Warning(
f"The setting {key} is defined at the top level of your configuration. It must be nested under the "
f"'BUGSINK' setting."
))
return errors

View File

@@ -1,7 +1,13 @@
from django.core.checks import Warning, register
import uuid
import logging
import threading
from django.conf import settings as django_settings # this _must_ be renamed, because we have a settings.py file
from snappea.settings import get_settings
logger = logging.getLogger("snappea.foreman")
@@ -48,3 +54,15 @@ registry = Registry()
localStorage = threading.local()
localStorage.uuid = str(uuid.uuid4())
thread_uuid = localStorage.uuid
@register("snappea")
def check_no_nested_settings_in_unnested_form(app_configs, **kwargs):
errors = []
for key in get_settings().keys():
if hasattr(django_settings, key):
errors.append(Warning(
f"The setting {key} is defined at the top level of your configuration. It must be nested under the "
f"'SNAPPEA' setting."
))
return errors