From 52957287635b787187b90e50c52c75bb000030bb Mon Sep 17 00:00:00 2001 From: aloftus23 Date: Wed, 20 Nov 2024 14:28:34 -0500 Subject: [PATCH] Initialize django before import in syncdb --- .../src/xfd_django/xfd_api/tasks/run_syncdb.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/src/xfd_django/xfd_api/tasks/run_syncdb.py b/backend/src/xfd_django/xfd_api/tasks/run_syncdb.py index 88c4279b..79dae249 100644 --- a/backend/src/xfd_django/xfd_api/tasks/run_syncdb.py +++ b/backend/src/xfd_django/xfd_api/tasks/run_syncdb.py @@ -7,7 +7,13 @@ from django.db import migrations, connection from django.db.migrations.executor import MigrationExecutor -# Custom Utilities +# Set the Django settings module +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xfd_django.settings") +os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" + +# Initialize Django +django.setup() + from xfd_api.tasks.syndb_helpers import manage_elasticsearch_indices, populate_sample_data @@ -16,13 +22,6 @@ def handler(event, context): Lambda handler to trigger syncdb. """ - # Set the Django settings module - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xfd_django.settings") - os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" - - # Initialize Django - django.setup() - # Parse arguments from the event dangerouslyforce = event.get("dangerouslyforce", False) populate = event.get("populate", False)