From cfcdd8826cb799701207ebab68e8aa06f11fe889 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:04:10 -0700 Subject: [PATCH] Squash bug --- src/registrar/models/domain.py | 5 +++-- src/registrar/tests/test_models_domain.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index aaafd6aa8..f7e76cbc4 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -2116,8 +2116,9 @@ class Domain(TimeStampedModel, DomainHelper): if db_contact.count() == 0: # Doesn't run custom save logic, just saves to DB try: - public_contact.save(skip_epp_save=True) - logger.info(f"Created a new PublicContact: {public_contact}") + with transaction.atomic(): + public_contact.save(skip_epp_save=True) + logger.info(f"Created a new PublicContact: {public_contact}") # In rare cases, _add_missing_contacts_if_unknown will cause a race condition with this function. # This is because it calls .save(), which is called here. # diff --git a/src/registrar/tests/test_models_domain.py b/src/registrar/tests/test_models_domain.py index bb1974464..8fde89fd0 100644 --- a/src/registrar/tests/test_models_domain.py +++ b/src/registrar/tests/test_models_domain.py @@ -349,6 +349,7 @@ class TestDomainCache(MockEppLib): class TestDomainCreation(MockEppLib): """Rule: An approved domain request must result in a domain""" + @less_console_noise_decorator def test_get_security_email_race_condition(self): """ Scenario: Two processes try to create the same security contact simultaneously