From 7d04c2baa001aeb144d08ffba38c701d83e00d10 Mon Sep 17 00:00:00 2001 From: pacnpal <183241239+pacnpal@users.noreply.github.com> Date: Sat, 27 Sep 2025 11:42:25 -0400 Subject: [PATCH] Refactor environment variable configurations for consistency; ensure proper type casting for DEBUG and ALLOWED_HOSTS settings. --- config/django/base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/config/django/base.py b/config/django/base.py index 00d7fe6c..6f52334f 100644 --- a/config/django/base.py +++ b/config/django/base.py @@ -7,6 +7,7 @@ from datetime import timedelta import sys import warnings from pathlib import Path +from typing import List from decouple import config # Suppress django-allauth deprecation warnings for dj_rest_auth compatibility @@ -19,14 +20,14 @@ warnings.filterwarnings( # Initialize environment variables with better defaults -DEBUG = config("DEBUG", default=True) +DEBUG = config("DEBUG", default=True, cast=bool) SECRET_KEY = config("SECRET_KEY") -ALLOWED_HOSTS = config("ALLOWED_HOSTS", default="localhost,127.0.0.1", cast=lambda v: [s.strip() for s in v.split(',') if s.strip()]) +ALLOWED_HOSTS = config("ALLOWED_HOSTS", default="localhost,127.0.0.1", cast=lambda v: [s.strip() for s in str(v).split(',') if s.strip()]) DATABASE_URL = config("DATABASE_URL") CACHE_URL = config("CACHE_URL", default="locmem://") EMAIL_URL = config("EMAIL_URL", default="console://") REDIS_URL = config("REDIS_URL", default="redis://127.0.0.1:6379/1") -CORS_ALLOWED_ORIGINS = config("CORS_ALLOWED_ORIGINS", default="", cast=lambda v: [s.strip() for s in v.split(',') if s.strip()]) +CORS_ALLOWED_ORIGINS = config("CORS_ALLOWED_ORIGINS", default="", cast=lambda v: [s.strip() for s in str(v).split(',') if s.strip()]) API_RATE_LIMIT_PER_MINUTE = config("API_RATE_LIMIT_PER_MINUTE", default=60) API_RATE_LIMIT_PER_HOUR = config("API_RATE_LIMIT_PER_HOUR", default=1000) CACHE_MIDDLEWARE_SECONDS = config("CACHE_MIDDLEWARE_SECONDS", default=300) @@ -55,7 +56,7 @@ SECRET_KEY = config("SECRET_KEY") # CSRF trusted origins CSRF_TRUSTED_ORIGINS = config( - "CSRF_TRUSTED_ORIGINS", default="", cast=lambda v: [s.strip() for s in v.split(',') if s.strip()] + "CSRF_TRUSTED_ORIGINS", default="", cast=lambda v: [s.strip() for s in str(v).split(',') if s.strip()] ) # Application definition