Fix bug with the DELETED state

This commit is contained in:
zandercymatics 2023-10-10 08:53:24 -06:00
parent 7f34a389f4
commit acd804b548
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -880,8 +880,8 @@ class Domain(TimeStampedModel, DomainHelper):
return self._handle_registrant_contact(desired_contact) return self._handle_registrant_contact(desired_contact)
_registry_id: str _registry_id: str = ""
if contact_type in contacts: if contacts is not None and contact_type in contacts:
_registry_id = contacts.get(contact_type) _registry_id = contacts.get(contact_type)
desired = PublicContact.objects.filter( desired = PublicContact.objects.filter(
@ -1293,6 +1293,47 @@ class Domain(TimeStampedModel, DomainHelper):
except RegistryError as e: except RegistryError as e:
logger.error(e) logger.error(e)
except TransitionNotAllowed:
# Fixes a bug with _fetch_cache trying to create
# a deleted domain, as cache gets cleared on delete.
# Instead, serve what we have locally.
if self.state == self.State.DELETED:
logger.warning("Attempted to create a deleted domain")
data = self._cache
choices = PublicContact.ContactTypeChoices
contacts_dict = {
choices.ADMINISTRATIVE: None,
choices.SECURITY: None,
choices.TECHNICAL: None,
}
registrant_id = ...
existing_contacts = PublicContact.objects.filter(
domain=self
)
if existing_contacts.count() > 0:
for choice in contacts_dict:
contacts_dict[choice] = existing_contacts.get(contact_type=choice).registry_id
# Edge case for registrant
registrant = PublicContact.ContactTypeChoices.REGISTRANT
registrant_id = existing_contacts.get(contact_type=registrant).registry_id
cache = {
"auth_info": getattr(data, "auth_info", ...),
"contacts": getattr(data, "contacts", contacts_dict),
"cr_date": getattr(data, "cr_date", ...),
"ex_date": getattr(data, "ex_date", ...),
"hosts": getattr(data, "hosts", ...),
"name": getattr(data, "name", self.name),
"registrant": getattr(data, "name", registrant_id),
"statuses": getattr(data, "statuses", ...),
"tr_date": getattr(data, "tr_date", ...),
"up_date": getattr(data, "up_date", ...),
}
cleaned = {k: v for k, v in cache.items() if v is not ...}
self._cache = cleaned
def _get_or_create_public_contact(self, public_contact: PublicContact): def _get_or_create_public_contact(self, public_contact: PublicContact):
"""Tries to find a PublicContact object in our DB. """Tries to find a PublicContact object in our DB.
If it can't, it'll create it. Returns PublicContact""" If it can't, it'll create it. Returns PublicContact"""