diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index e856a4911..3f69feecd 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -1686,6 +1686,13 @@ class Domain(TimeStampedModel, DomainHelper): logger.error("Error _delete_hosts_if_not_used, code was %s error was %s" % (e.code, e)) def _fix_unknown_state(self, cleaned): + """ + _fix_unknown_state: Calls _add_missing_contacts_if_unknown + to add contacts in as needed (or return an error). Otherwise + if we are able to add contacts and the state is out of UNKNOWN + and (and should be into DNS_NEEDED), we double check the + current state and # of nameservers and update the state from there + """ try: self._add_missing_contacts_if_unknown(cleaned) @@ -1694,7 +1701,7 @@ class Domain(TimeStampedModel, DomainHelper): "%s couldn't _add_missing_contacts_if_unknown, error was %s." "Domain will still be in UNKNOWN state." % (self.name, e) ) - if len(self.nameservers) >= 2: + if len(self.nameservers) >= 2 and (self.state != self.State.READY): self.ready() self.save() diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 446762800..20131cfad 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -1064,7 +1064,6 @@ class MockEppLib(TestCase): mockDataSecurityContact = mockDataInfoDomain.dummyInfoContactResultData( id="securityContact", email="security@mail.gov", cr_date=datetime(2023, 5, 25, 19, 45, 35), pw="lastPw" ) - # print("!! mockDataInfoContact is", mockDataInfoContact) InfoDomainWithContacts = fakedEppObject( "fakePw", cr_date=make_aware(datetime(2023, 5, 25, 19, 45, 35)), diff --git a/src/registrar/tests/test_models_domain.py b/src/registrar/tests/test_models_domain.py index a92781694..abad6f57e 100644 --- a/src/registrar/tests/test_models_domain.py +++ b/src/registrar/tests/test_models_domain.py @@ -339,6 +339,7 @@ class TestDomainCache(MockEppLib): """ with less_console_noise(): domain, _ = Domain.objects.get_or_create(name="defaulttechnical.gov") + # trigger the getter _ = domain.nameservers self.assertEqual(domain.state, Domain.State.DNS_NEEDED) self.assertEqual(PublicContact.objects.filter(domain=domain.id).count(), 2)