From 13cd50c8b844e069b2281958d0f6305bbf9850a1 Mon Sep 17 00:00:00 2001 From: Haresh Kainth Date: Sat, 7 Dec 2024 00:11:14 +0000 Subject: [PATCH] Initialize Django setup earlier in manage.py Relocate Django setup to the top of manage.py file to ensure that it is configured before running administrative tasks. This change avoids potential Django configuration issues by setting the environment consistently during the application start-up. Adjusted celery.py to remove redundant Django setup, streamlining the initialization process. --- fbr/config/celery.py | 3 --- fbr/manage.py | 9 ++++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fbr/config/celery.py b/fbr/config/celery.py index fd3f573..62cbdf3 100644 --- a/fbr/config/celery.py +++ b/fbr/config/celery.py @@ -4,10 +4,7 @@ from celery.schedules import crontab from dbt_copilot_python.celery_health_check import healthcheck -import django - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") -django.setup() celery_app = Celery("fbr_celery") diff --git a/fbr/manage.py b/fbr/manage.py index 6326a7c..f03979a 100755 --- a/fbr/manage.py +++ b/fbr/manage.py @@ -1,12 +1,19 @@ +# flake8: noqa + #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" import os import sys +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") +import django + +django.setup() + def main(): """Run administrative tasks.""" - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") + try: from django.core.management import execute_from_command_line except ImportError as exc: