Remove load fixtures signal on migrate, add load command to docker compose, add DEBUG env check to load.py

This commit is contained in:
Rachid Mrad 2023-09-01 14:20:06 -04:00
parent 7b8eee7b2f
commit 9ca424d30c
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF
3 changed files with 10 additions and 15 deletions

View file

@ -54,6 +54,7 @@ services:
# command: "python" # command: "python"
command: > command: >
bash -c " python manage.py migrate && bash -c " python manage.py migrate &&
python manage.py load &&
python manage.py runserver 0.0.0.0:8080" python manage.py runserver 0.0.0.0:8080"
db: db:

View file

@ -2,6 +2,7 @@ import logging
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from auditlog.context import disable_auditlog # type: ignore from auditlog.context import disable_auditlog # type: ignore
from django.conf import settings
from registrar.fixtures import UserFixture, DomainApplicationFixture, DomainFixture from registrar.fixtures import UserFixture, DomainApplicationFixture, DomainFixture
@ -12,8 +13,11 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
# django-auditlog has some bugs with fixtures # django-auditlog has some bugs with fixtures
# https://github.com/jazzband/django-auditlog/issues/17 # https://github.com/jazzband/django-auditlog/issues/17
if settings.DEBUG:
with disable_auditlog(): with disable_auditlog():
UserFixture.load() UserFixture.load()
DomainApplicationFixture.load() DomainApplicationFixture.load()
DomainFixture.load() DomainFixture.load()
logger.info("All fixtures loaded.") logger.info("All fixtures loaded.")
else:
logger.warn("Refusing to load fixture data in a non DEBUG env")

View file

@ -1,6 +1,5 @@
import logging import logging
from django.conf import settings
from django.core.management import call_command from django.core.management import call_command
from django.db.models.signals import post_save, post_migrate from django.db.models.signals import post_save, post_migrate
from django.dispatch import receiver from django.dispatch import receiver
@ -56,12 +55,3 @@ def handle_profile(sender, instance, **kwargs):
f" Picking #{contacts[0].id} for User #{instance.id}." f" Picking #{contacts[0].id} for User #{instance.id}."
) )
@receiver(post_migrate)
def handle_loaddata(**kwargs):
"""Attempt to load test fixtures when in DEBUG mode."""
if settings.DEBUG:
try:
call_command("load")
except Exception as e:
logger.warning(e)