From 9686b94bca57ab102839920bda93c29f4daf52b0 Mon Sep 17 00:00:00 2001 From: Bernard Szabo Date: Wed, 8 Jan 2025 17:22:36 -0500 Subject: [PATCH] Try locating the django config file relative to the script --- tubular/scripts/dd_synthetic_tests.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tubular/scripts/dd_synthetic_tests.py b/tubular/scripts/dd_synthetic_tests.py index 98d1f60b..143ed9dd 100644 --- a/tubular/scripts/dd_synthetic_tests.py +++ b/tubular/scripts/dd_synthetic_tests.py @@ -181,7 +181,28 @@ def run_synthetic_tests(enable_automated_rollbacks, slack_notification_channel): try: synthetic_tests_waffle_flag_name = "TUBULAR_ENABLE_SYNTHETIC_TESTS" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tubular.envs.production') + + # Get the absolute path of the current script + current_script_path = os.path.abspath(__file__) + + # Get the directory of the current script + current_dir = os.path.dirname(current_script_path) + + # Get the parent directory of the current script's folder + parent_dir = os.path.dirname(current_dir) + + # Construct the path to the production settings module + production_settings_path = os.path.join(parent_dir, 'envs', 'production.py') + + # Ensure the production settings module exists + if not os.path.exists(production_settings_path): + raise FileNotFoundError(f"Settings module not found: {production_settings_path}") + + # Add the parent directory to the Python path + sys.path.insert(0, parent_dir) + + # Set the default DJANGO_SETTINGS_MODULE environment variable + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'envs.production') waffle_flag_enabled = get_setting(synthetic_tests_waffle_flag_name, False) logging.info(f"{waffle_flag_enabled=}")