mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-20 11:29:25 +02:00
Fix bulk add bug
This commit is contained in:
parent
661b765f0e
commit
642c23d3b7
2 changed files with 39 additions and 12 deletions
|
@ -640,8 +640,20 @@ class Command(BaseCommand):
|
|||
{TerminalColors.ENDC}"""
|
||||
)
|
||||
|
||||
# First, save all Domain objects to the database
|
||||
Domain.objects.bulk_create(domains_to_create)
|
||||
DomainInvitation.objects.bulk_create(domain_invitations_to_create)
|
||||
#DomainInvitation.objects.bulk_create(domain_invitations_to_create)
|
||||
|
||||
# Then, create DomainInvitation objects
|
||||
for invitation in domain_invitations_to_create:
|
||||
existing_domain = Domain.objects.filter(name=invitation.domain.name)
|
||||
# Make sure the related Domain object is saved
|
||||
if existing_domain.exists():
|
||||
invitation.domain = existing_domain.get()
|
||||
else:
|
||||
# Raise an err for now
|
||||
raise Exception(f"Domain {existing_domain} wants to be added but doesn't exist in the DB")
|
||||
invitation.save()
|
||||
|
||||
# ======================================================
|
||||
# ================= DOMAIN INFORMATION =================
|
||||
|
|
|
@ -150,6 +150,7 @@ class LoadExtraTransitionDomain:
|
|||
raise ValueError("No TransitionDomain objects exist.")
|
||||
|
||||
updated_transition_domains = []
|
||||
failed_transition_domains = []
|
||||
for transition_domain in all_transition_domains:
|
||||
domain_name = transition_domain.domain_name.upper()
|
||||
updated_transition_domain = transition_domain
|
||||
|
@ -174,33 +175,47 @@ class LoadExtraTransitionDomain:
|
|||
domain_name, transition_domain
|
||||
)
|
||||
|
||||
# Check if the instance has changed before saving
|
||||
#if updated_transition_domain.__dict__ != transition_domain.__dict__:
|
||||
updated_transition_domain.save()
|
||||
updated_transition_domains.append(updated_transition_domain)
|
||||
|
||||
self.parse_logs.display_logs_by_domain_name(domain_name)
|
||||
logger.info(
|
||||
f"{TerminalColors.OKCYAN}"
|
||||
f"Successfully updated {domain_name}"
|
||||
f"{TerminalColors.ENDC}"
|
||||
)
|
||||
updated_transition_domains.append(updated_transition_domain)
|
||||
|
||||
|
||||
# If we run into an exception on this domain,
|
||||
# Just skip over it and log that it happened.
|
||||
except Exception as err:
|
||||
logger.debug(err)
|
||||
logger.info(
|
||||
logger.error(
|
||||
f"{TerminalColors.FAIL}"
|
||||
f"Exception encountered on {domain_name}. Could not update."
|
||||
f"{TerminalColors.ENDC}"
|
||||
)
|
||||
raise err
|
||||
logger.info(
|
||||
f"""{TerminalColors.OKGREEN}
|
||||
============= FINISHED ===============
|
||||
updated {len(updated_transition_domains)} transition domain entries
|
||||
{TerminalColors.ENDC}
|
||||
"""
|
||||
)
|
||||
failed_transition_domains.append(domain_name)
|
||||
|
||||
failed_count = len(failed_transition_domains)
|
||||
if failed_count == 0:
|
||||
logger.info(
|
||||
f"""{TerminalColors.OKGREEN}
|
||||
============= FINISHED ===============
|
||||
Updated {len(updated_transition_domains)} transition domain entries
|
||||
{TerminalColors.ENDC}
|
||||
"""
|
||||
)
|
||||
else:
|
||||
logger.error(
|
||||
f"""{TerminalColors.FAIL}
|
||||
============= FINISHED WITH ERRORS ===============
|
||||
Updated {len(updated_transition_domains)} transition domain entries,
|
||||
Failed to update {failed_count} transition domain entries
|
||||
{TerminalColors.ENDC}
|
||||
"""
|
||||
)
|
||||
|
||||
def parse_creation_expiration_data(self, domain_name, transition_domain):
|
||||
"""Grabs expiration_date from the parsed files and associates it
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue