This commit is contained in:
zandercymatics 2023-11-20 11:53:57 -07:00
parent 2e44a9099a
commit 493c03e7d4
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 13 additions and 7 deletions

View file

@ -64,7 +64,7 @@ class Command(BaseCommand):
for key, value in data.items():
if value is None or value.strip() == "":
continue
# If any key in skipped_fields has a value, then
# we override what is specified in the JSON.
if options not in skipped_fields:
@ -163,7 +163,7 @@ class Command(BaseCommand):
# Start with all DomainInformation objects
domain_informations = DomainInformation.objects.all()
domain_informations_dict = {di.domain.name: di for di in domain_informations}
domain_informations_dict = {di.domain.name: di for di in domain_informations if di.domain is not None}
# Then, use each domain object to map TransitionDomain <--> DomainInformation
# Fetches all DomainInformations in one query.
@ -177,7 +177,7 @@ class Command(BaseCommand):
zipcode__isnull=True,
)
filtered_domain_informations_dict = {di.domain.name: di for di in domain_informations}
filtered_domain_informations_dict = {di.domain.name: di for di in domain_informations if di.domain is not None}
for item in transition_domains:
if item.domain_name not in domain_informations_dict:
logger.error(f"Could not add {item.domain_name}. Domain does not exist.")
@ -196,6 +196,9 @@ class Command(BaseCommand):
# Based on the current domain, grab the right DomainInformation object.
current_domain_information = filtered_domain_informations_dict[item.domain_name]
if current_domain_information.domain is None or current_domain_information.domain.name is None:
raise LoadOrganizationError(code=LoadOrganizationErrorCodes.DOMAIN_NAME_WAS_NONE)
# Update fields
current_domain_information.address_line1 = item.address_line
current_domain_information.city = item.city

View file

@ -9,7 +9,7 @@ import logging
import os
import sys
from typing import Dict
from typing import Dict, List
from django.core.paginator import Paginator
from registrar.models.transition_domain import TransitionDomain
from registrar.utility.errors import LoadOrganizationError, LoadOrganizationErrorCodes
@ -781,7 +781,7 @@ class OrganizationDataLoader:
# options.infer_filenames will always be false when not SETTING.DEBUG
self.parsed_data.parse_all_files(options.infer_filenames)
self.tds_to_update = []
self.tds_to_update: List[TransitionDomain] = []
def update_organization_data_for_all(self):
"""Updates org data for all TransitionDomains"""
@ -870,7 +870,7 @@ class OrganizationDataLoader:
return transition_domain
def get_org_info(self, domain_name) -> OrganizationAdhoc:
def get_org_info(self, domain_name) -> OrganizationAdhoc | None:
"""Maps an id given in get_domain_data to a organization_adhoc
record which has its corresponding definition"""
# Get a row in the domain_additional file. The id is the domain_name.

View file

@ -64,9 +64,11 @@ class LoadOrganizationErrorCodes(IntEnum):
- 2 UPDATE_DOMAIN_INFO_FAILED
- 3 EMPTY_TRANSITION_DOMAIN_TABLE
"""
TRANSITION_DOMAINS_NOT_FOUND = 1
UPDATE_DOMAIN_INFO_FAILED = 2
EMPTY_TRANSITION_DOMAIN_TABLE = 3
DOMAIN_NAME_WAS_NONE = 4
class LoadOrganizationError(Exception):
@ -79,7 +81,8 @@ class LoadOrganizationError(Exception):
"Could not find all desired TransitionDomains. " "(Possible data corruption?)"
),
LoadOrganizationErrorCodes.UPDATE_DOMAIN_INFO_FAILED: "Failed to update DomainInformation",
LoadOrganizationErrorCodes.EMPTY_TRANSITION_DOMAIN_TABLE: "No TransitionDomains exist. Cannot update."
LoadOrganizationErrorCodes.EMPTY_TRANSITION_DOMAIN_TABLE: "No TransitionDomains exist. Cannot update.",
LoadOrganizationErrorCodes.DOMAIN_NAME_WAS_NONE: "DomainInformation was updated, but domain was None",
}
def __init__(self, *args, code=None, **kwargs):