prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Fixtures loads 8 times on docker-compose up
  ### Current Behavior
  
  When starting up the application, the console log shows that the fixtures file is executed 8 times in a row. However, current logic on the fixtures file is preventing duplicate entries in the database.
  
  ### Expected Behavior
  
  Data should just be loaded into the db once when using fixtures.
  
  ### Steps to Reproduce
  
  1. locally run docker-compose up
  2. observe the logs
  3. see that the logs for loading domain application, users, etc are repeated 8 times each. Also note the warning messages that show an attempt was made to enter data that already exists in the db.
  
  
  ### Environment
  
  local & on sandbox (see the deploy logs)
  
  ### Additional Context
  
  see this [slack thread](https://cisa-corp.slack.com/archives/C05BGB4L5NF/p1687988129781299)
  
  ### Issue Links
  
  _No response_
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/registrar/management/commands/load.py`
  Content:
  ```
  1 import logging
  2 
  3 from django.core.management.base import BaseCommand
  4 from auditlog.context import disable_auditlog  # type: ignore
  5 
  6 from registrar.fixtures import UserFixture, DomainApplicationFixture, DomainFixture
  7 
  8 logger = logging.getLogger(__name__)
  9 
  10 
  11 class Command(BaseCommand):
  12     def handle(self, *args, **options):
  13         # django-auditlog has some bugs with fixtures
  14         # https://github.com/jazzband/django-auditlog/issues/17
  15         with disable_auditlog():
  16             UserFixture.load()
  17             DomainApplicationFixture.load()
  18             DomainFixture.load()
  19             logger.info("All fixtures loaded.")
  20
  ```
  
  Path: `src/registrar/signals.py`
  Content:
  ```
  1 import logging
  2 
  3 from django.conf import settings
  4 from django.core.management import call_command
  5 from django.db.models.signals import post_save, post_migrate
  6 from django.dispatch import receiver
  7 
  8 from .models import User, Contact
  9 
  10 
  11 logger = logging.getLogger(__name__)
  12 
  13 
  14 @receiver(post_save, sender=User)
  15 def handle_profile(sender, instance, **kwargs):
  16     """Method for when a User is saved.
  17 
  18     A first time registrant may have been invited, so we'll search for a matching
  19     Contact record, by email address, and associate them, if possible.
  20 
  21     A first time registrant may not have a matching Contact, so we'll create one,
  22     copying the contact values we received from Login.gov in order to initialize it.
  23 
  24     During subsequent login, a User record may be updated with new data from Login.gov,
  25     but in no case will we update contact values on an existing Contact record.
  26     """
  27 
  28     first_name = getattr(instance, "first_name", "")
  29     last_name = getattr(instance, "last_name", "")
  30     email = getattr(instance, "email", "")
  31     phone = getattr(instance, "phone", "")
  32 
  33     is_new_user = kwargs.get("created", False)
  34 
  35     if is_new_user:
  36         contacts = Contact.objects.filter(email=email)
  37     else:
  38         contacts = Contact.objects.filter(user=instance)
  39 
  40     if len(contacts) == 0:  # no matching contact
  41         Contact.objects.create(
  42             user=instance,
  43             first_name=first_name,
  44             last_name=last_name,
  45             email=email,
  46             phone=phone,
  47         )
  48 
  49     if len(contacts) >= 1 and is_new_user:  # a matching contact
  50         contacts[0].user = instance
  51         contacts[0].save()
  52 
  53         if len(contacts) > 1:  # multiple matches
  54             logger.warning(
  55                 "There are multiple Contacts with the same email address."
  56                 f" Picking #{contacts[0].id} for User #{instance.id}."
  57             )
  58 
  59 
  60 @receiver(post_migrate)
  61 def handle_loaddata(**kwargs):
  62     """Attempt to load test fixtures when in DEBUG mode."""
  63     if settings.DEBUG:
  64         try:
  65             call_command("load")
  66         except Exception as e:
  67             logger.warning(e)
  68
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/registrar/management/commands/load.py b/src/registrar/management/commands/load.py
  --- a/src/registrar/management/commands/load.py
  +++ b/src/registrar/management/commands/load.py
  @@ -2,6 +2,7 @@
   
   from django.core.management.base import BaseCommand
   from auditlog.context import disable_auditlog  # type: ignore
  +from django.conf import settings
   
   from registrar.fixtures import UserFixture, DomainApplicationFixture, DomainFixture
   
  @@ -12,8 +13,11 @@
       def handle(self, *args, **options):
           # django-auditlog has some bugs with fixtures
           # https://github.com/jazzband/django-auditlog/issues/17
  -        with disable_auditlog():
  -            UserFixture.load()
  -            DomainApplicationFixture.load()
  -            DomainFixture.load()
  -            logger.info("All fixtures loaded.")
  +        if settings.DEBUG:
  +            with disable_auditlog():
  +                UserFixture.load()
  +                DomainApplicationFixture.load()
  +                DomainFixture.load()
  +                logger.info("All fixtures loaded.")
  +        else:
  +            logger.warn("Refusing to load fixture data in a non DEBUG env")
  diff --git a/src/registrar/signals.py b/src/registrar/signals.py
  --- a/src/registrar/signals.py
  +++ b/src/registrar/signals.py
  @@ -1,8 +1,6 @@
   import logging
   
  -from django.conf import settings
  -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
   from django.dispatch import receiver
   
   from .models import User, Contact
  @@ -55,13 +53,3 @@
                   "There are multiple Contacts with the same email address."
                   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)
  
verification_info: {"golden_diff": "diff --git a/src/registrar/management/commands/load.py b/src/registrar/management/commands/load.py\n--- a/src/registrar/management/commands/load.py\n+++ b/src/registrar/management/commands/load.py\n@@ -2,6 +2,7 @@\n \n from django.core.management.base import BaseCommand\n from auditlog.context import disable_auditlog  # type: ignore\n+from django.conf import settings\n \n from registrar.fixtures import UserFixture, DomainApplicationFixture, DomainFixture\n \n@@ -12,8 +13,11 @@\n     def handle(self, *args, **options):\n         # django-auditlog has some bugs with fixtures\n         # https://github.com/jazzband/django-auditlog/issues/17\n-        with disable_auditlog():\n-            UserFixture.load()\n-            DomainApplicationFixture.load()\n-            DomainFixture.load()\n-            logger.info(\"All fixtures loaded.\")\n+        if settings.DEBUG:\n+            with disable_auditlog():\n+                UserFixture.load()\n+                DomainApplicationFixture.load()\n+                DomainFixture.load()\n+                logger.info(\"All fixtures loaded.\")\n+        else:\n+            logger.warn(\"Refusing to load fixture data in a non DEBUG env\")\ndiff --git a/src/registrar/signals.py b/src/registrar/signals.py\n--- a/src/registrar/signals.py\n+++ b/src/registrar/signals.py\n@@ -1,8 +1,6 @@\n import logging\n \n-from django.conf import settings\n-from django.core.management import call_command\n-from django.db.models.signals import post_save, post_migrate\n+from django.db.models.signals import post_save\n from django.dispatch import receiver\n \n from .models import User, Contact\n@@ -55,13 +53,3 @@\n                 \"There are multiple Contacts with the same email address.\"\n                 f\" Picking #{contacts[0].id} for User #{instance.id}.\"\n             )\n-\n-\n-@receiver(post_migrate)\n-def handle_loaddata(**kwargs):\n-    \"\"\"Attempt to load test fixtures when in DEBUG mode.\"\"\"\n-    if settings.DEBUG:\n-        try:\n-            call_command(\"load\")\n-        except Exception as e:\n-            logger.warning(e)\n", "issue": "Fixtures loads 8 times on docker-compose up\n### Current Behavior\n\nWhen starting up the application, the console log shows that the fixtures file is executed 8 times in a row. However, current logic on the fixtures file is preventing duplicate entries in the database.\n\n### Expected Behavior\n\nData should just be loaded into the db once when using fixtures.\n\n### Steps to Reproduce\n\n1. locally run docker-compose up\r\n2. observe the logs\r\n3. see that the logs for loading domain application, users, etc are repeated 8 times each. Also note the warning messages that show an attempt was made to enter data that already exists in the db.\r\n\n\n### Environment\n\nlocal & on sandbox (see the deploy logs)\n\n### Additional Context\n\nsee this [slack thread](https://cisa-corp.slack.com/archives/C05BGB4L5NF/p1687988129781299)\n\n### Issue Links\n\n_No response_\n", "before_files": [{"content": "import logging\n\nfrom django.core.management.base import BaseCommand\nfrom auditlog.context import disable_auditlog  # type: ignore\n\nfrom registrar.fixtures import UserFixture, DomainApplicationFixture, DomainFixture\n\nlogger = logging.getLogger(__name__)\n\n\nclass Command(BaseCommand):\n    def handle(self, *args, **options):\n        # django-auditlog has some bugs with fixtures\n        # https://github.com/jazzband/django-auditlog/issues/17\n        with disable_auditlog():\n            UserFixture.load()\n            DomainApplicationFixture.load()\n            DomainFixture.load()\n            logger.info(\"All fixtures loaded.\")\n", "path": "src/registrar/management/commands/load.py"}, {"content": "import logging\n\nfrom django.conf import settings\nfrom django.core.management import call_command\nfrom django.db.models.signals import post_save, post_migrate\nfrom django.dispatch import receiver\n\nfrom .models import User, Contact\n\n\nlogger = logging.getLogger(__name__)\n\n\n@receiver(post_save, sender=User)\ndef handle_profile(sender, instance, **kwargs):\n    \"\"\"Method for when a User is saved.\n\n    A first time registrant may have been invited, so we'll search for a matching\n    Contact record, by email address, and associate them, if possible.\n\n    A first time registrant may not have a matching Contact, so we'll create one,\n    copying the contact values we received from Login.gov in order to initialize it.\n\n    During subsequent login, a User record may be updated with new data from Login.gov,\n    but in no case will we update contact values on an existing Contact record.\n    \"\"\"\n\n    first_name = getattr(instance, \"first_name\", \"\")\n    last_name = getattr(instance, \"last_name\", \"\")\n    email = getattr(instance, \"email\", \"\")\n    phone = getattr(instance, \"phone\", \"\")\n\n    is_new_user = kwargs.get(\"created\", False)\n\n    if is_new_user:\n        contacts = Contact.objects.filter(email=email)\n    else:\n        contacts = Contact.objects.filter(user=instance)\n\n    if len(contacts) == 0:  # no matching contact\n        Contact.objects.create(\n            user=instance,\n            first_name=first_name,\n            last_name=last_name,\n            email=email,\n            phone=phone,\n        )\n\n    if len(contacts) >= 1 and is_new_user:  # a matching contact\n        contacts[0].user = instance\n        contacts[0].save()\n\n        if len(contacts) > 1:  # multiple matches\n            logger.warning(\n                \"There are multiple Contacts with the same email address.\"\n                f\" Picking #{contacts[0].id} for User #{instance.id}.\"\n            )\n\n\n@receiver(post_migrate)\ndef handle_loaddata(**kwargs):\n    \"\"\"Attempt to load test fixtures when in DEBUG mode.\"\"\"\n    if settings.DEBUG:\n        try:\n            call_command(\"load\")\n        except Exception as e:\n            logger.warning(e)\n", "path": "src/registrar/signals.py"}], "after_files": [{"content": "import logging\n\nfrom django.core.management.base import BaseCommand\nfrom auditlog.context import disable_auditlog  # type: ignore\nfrom django.conf import settings\n\nfrom registrar.fixtures import UserFixture, DomainApplicationFixture, DomainFixture\n\nlogger = logging.getLogger(__name__)\n\n\nclass Command(BaseCommand):\n    def handle(self, *args, **options):\n        # django-auditlog has some bugs with fixtures\n        # https://github.com/jazzband/django-auditlog/issues/17\n        if settings.DEBUG:\n            with disable_auditlog():\n                UserFixture.load()\n                DomainApplicationFixture.load()\n                DomainFixture.load()\n                logger.info(\"All fixtures loaded.\")\n        else:\n            logger.warn(\"Refusing to load fixture data in a non DEBUG env\")\n", "path": "src/registrar/management/commands/load.py"}, {"content": "import logging\n\nfrom django.db.models.signals import post_save\nfrom django.dispatch import receiver\n\nfrom .models import User, Contact\n\n\nlogger = logging.getLogger(__name__)\n\n\n@receiver(post_save, sender=User)\ndef handle_profile(sender, instance, **kwargs):\n    \"\"\"Method for when a User is saved.\n\n    A first time registrant may have been invited, so we'll search for a matching\n    Contact record, by email address, and associate them, if possible.\n\n    A first time registrant may not have a matching Contact, so we'll create one,\n    copying the contact values we received from Login.gov in order to initialize it.\n\n    During subsequent login, a User record may be updated with new data from Login.gov,\n    but in no case will we update contact values on an existing Contact record.\n    \"\"\"\n\n    first_name = getattr(instance, \"first_name\", \"\")\n    last_name = getattr(instance, \"last_name\", \"\")\n    email = getattr(instance, \"email\", \"\")\n    phone = getattr(instance, \"phone\", \"\")\n\n    is_new_user = kwargs.get(\"created\", False)\n\n    if is_new_user:\n        contacts = Contact.objects.filter(email=email)\n    else:\n        contacts = Contact.objects.filter(user=instance)\n\n    if len(contacts) == 0:  # no matching contact\n        Contact.objects.create(\n            user=instance,\n            first_name=first_name,\n            last_name=last_name,\n            email=email,\n            phone=phone,\n        )\n\n    if len(contacts) >= 1 and is_new_user:  # a matching contact\n        contacts[0].user = instance\n        contacts[0].save()\n\n        if len(contacts) > 1:  # multiple matches\n            logger.warning(\n                \"There are multiple Contacts with the same email address.\"\n                f\" Picking #{contacts[0].id} for User #{instance.id}.\"\n            )\n", "path": "src/registrar/signals.py"}]}