fairdm.conf.checks#

System checks that validate the configuration and service availability.

Provides fail-fast validation for production and graceful degradation for development.

Module Contents#

Classes#

DeployTags

Custom tags for deployment-related checks.

Functions#

check_database_configured

Report fairdm.E100 when DATABASES[‘default’] is not configured.

check_database_production_ready

Report fairdm.E101 when the database is not PostgreSQL with PostGIS.

check_database_usable

Report fairdm.E102 when DATABASES[‘default’] has no NAME, as a malformed DATABASE_URL leaves it.

check_cache_backend

Report fairdm.E200 when the cache is not a shared backend, or is the baseline’s placeholder.

check_secret_key_exists

Report fairdm.E001 when SECRET_KEY is empty, insecure or too short.

check_allowed_hosts_configured

Report fairdm.E003 when ALLOWED_HOSTS is empty.

check_allowed_hosts_secure

Report fairdm.E004 when ALLOWED_HOSTS contains the wildcard ‘*’.

check_debug_false

Report fairdm.E005 when DEBUG is True.

check_backup_key_present

Report fairdm.E700 when BACKUP_PUBLIC_KEY is not set.

check_backup_key_usable

Report fairdm.E701 when BACKUP_PUBLIC_KEY cannot be encrypted to, or gpg is missing.

check_backup_storage_is_remote

Report fairdm.W700 when production keeps backups on the local disk.

check_secure_cookie_prefixes_match_secure_flag

Report fairdm.E006 when a __Secure- or __Host- cookie name is paired with an insecure flag.

check_api_proxy_count

Report fairdm.W601 when REST_FRAMEWORK has no NUM_PROXIES.

check_celery_broker

Report fairdm.E300 when CELERY_BROKER_URL is not configured.

check_celery_async

Report fairdm.E301 when CELERY_TASK_ALWAYS_EAGER is True.

check_portal_roles_present

Report fairdm.E500 when a shipped portal role is missing from the database.

check_dev_accounts_absent

Report fairdm.E501 when development accounts exist outside development.

parler_languages_errors

Return fairdm.E400 for the given setting values.

raise_on_parler_languages_mismatch

Refuse to continue when PARLER_LANGUAGES and LANGUAGES disagree, naming both.

check_parler_languages_subset_of_languages

Report fairdm.E400 when PARLER_LANGUAGES names a code LANGUAGES lacks.

validate_addon_module

Validate that an addon’s setup module can be found.

Data#

API#

logger#

‘getLogger(…)’

class DeployTags[source]#

Bases: django.core.checks.Tags

Custom tags for deployment-related checks.

deploy#

‘deploy’

production_critical#

‘production_critical’

POSTGIS_ENGINE#

‘django.contrib.gis.db.backends.postgis’

check_database_configured(app_configs, **kwargs)[source]#

Report fairdm.E100 when DATABASES[‘default’] is not configured.

check_database_production_ready(app_configs, **kwargs)[source]#

Report fairdm.E101 when the database is not PostgreSQL with PostGIS.

check_database_usable(app_configs, **kwargs)[source]#

Report fairdm.E102 when DATABASES[‘default’] has no NAME, as a malformed DATABASE_URL leaves it.

SHARED_CACHE_BACKENDS#

‘frozenset(…)’

UNCONFIGURED_REDIS_LOCATION#

‘redis://unconfigured.invalid:6379/0’

check_cache_backend(app_configs, **kwargs)[source]#

Report fairdm.E200 when the cache is not a shared backend, or is the baseline’s placeholder.

INSECURE_SECRET_KEY_PREFIX#

‘django-insecure-’

MINIMUM_SECRET_KEY_LENGTH#

50

check_secret_key_exists(app_configs, **kwargs)[source]#

Report fairdm.E001 when SECRET_KEY is empty, insecure or too short.

check_allowed_hosts_configured(app_configs, **kwargs)[source]#

Report fairdm.E003 when ALLOWED_HOSTS is empty.

check_allowed_hosts_secure(app_configs, **kwargs)[source]#

Report fairdm.E004 when ALLOWED_HOSTS contains the wildcard ‘*’.

check_debug_false(app_configs, **kwargs)[source]#

Report fairdm.E005 when DEBUG is True.

check_backup_key_present(app_configs, **kwargs)[source]#

Report fairdm.E700 when BACKUP_PUBLIC_KEY is not set.

check_backup_key_usable(app_configs, **kwargs)[source]#

Report fairdm.E701 when BACKUP_PUBLIC_KEY cannot be encrypted to, or gpg is missing.

check_backup_storage_is_remote(app_configs, **kwargs)[source]#

Report fairdm.W700 when production keeps backups on the local disk.

(‘__Secure-’, ‘__Host-’)

((‘CSRF_COOKIE_NAME’, ‘CSRF_COOKIE_SECURE’), (‘SESSION_COOKIE_NAME’, ‘SESSION_COOKIE_SECURE’), (‘LAN…

Report fairdm.E006 when a __Secure- or __Host- cookie name is paired with an insecure flag.

check_api_proxy_count(app_configs, **kwargs)[source]#

Report fairdm.W601 when REST_FRAMEWORK has no NUM_PROXIES.

Without it, the API takes a caller’s address from the X-Forwarded-For header, which the caller writes, so the request limits can be avoided. Any value an operator sets, 0 and None included, is a decision and is left alone.

check_celery_broker(app_configs, **kwargs)[source]#

Report fairdm.E300 when CELERY_BROKER_URL is not configured.

check_celery_async(app_configs, **kwargs)[source]#

Report fairdm.E301 when CELERY_TASK_ALWAYS_EAGER is True.

MIGRATE_COMMAND_NAME#

‘migrate’

PRE_MIGRATE_COMMAND_NAMES#

‘frozenset(…)’

UNREADABLE_DATABASE#

()

check_portal_roles_present(app_configs, **kwargs)[source]#

Report fairdm.E500 when a shipped portal role is missing from the database.

check_dev_accounts_absent(app_configs, **kwargs)[source]#

Report fairdm.E501 when development accounts exist outside development.

parler_languages_errors(languages, parler_languages, parler_default_language_code=None) → list[django.core.checks.Error][source]#

Return fairdm.E400 for the given setting values.

Takes values rather than reading settings so the rule can run before settings load, as raise_on_parler_languages_mismatch does.

Args: languages: The LANGUAGES setting. parler_languages: The PARLER_LANGUAGES setting. parler_default_language_code: The PARLER_DEFAULT_LANGUAGE_CODE setting.

Returns: One error naming the missing codes, or an empty list when the settings agree.

raise_on_parler_languages_mismatch(languages, parler_languages, parler_default_language_code=None) → None[source]#

Refuse to continue when PARLER_LANGUAGES and LANGUAGES disagree, naming both.

Called from fairdm.conf.setup() on the composed settings, the only point ahead of every app’s models, and again from FairDMConfig.import_models() on the loaded settings, which sees assignments a portal makes after setup(). A portal that does both still gets parler’s own error.

Args: languages: The LANGUAGES setting. parler_languages: The PARLER_LANGUAGES setting. parler_default_language_code: The PARLER_DEFAULT_LANGUAGE_CODE setting.

Raises: SystemCheckError: The two settings disagree.

check_parler_languages_subset_of_languages(app_configs, **kwargs)[source]#

Report fairdm.E400 when PARLER_LANGUAGES names a code LANGUAGES lacks.

validate_addon_module(addon_name: str, module_path: str, env_profile: str) → bool[source]#

Validate that an addon’s setup module can be found.

Only checks that the module can be found, not imported, because addon setup modules are executed via split_settings.include(), which supplies the scope they need.

Args: addon_name: The name of the addon package. module_path: The path to the addon’s setup module. env_profile: The resolved environment name (e.g. “production”, “development”).

Returns: True if the module is valid, False otherwise.

Raises: ImproperlyConfigured: The module is invalid and the environment is production. ModuleNotFoundError: The module cannot be found. Handled inside this function, so callers see False, or ImproperlyConfigured in production.