Skip to content

Commit

Permalink
Merge pull request #1803 from cisagov/za/1795-staging-data-domaininfo…
Browse files Browse the repository at this point in the history
…rmation-overwritten

(Hot fix) Ticket #1795: DomainInformation being overwritten in some circumstances
  • Loading branch information
zandercymatics authored Feb 21, 2024
2 parents 92bd8f5 + 0d23007 commit f72e81a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/registrar/models/domain_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ def create_from_da(cls, domain_application: DomainApplication, domain=None):
else:
da_many_to_many_dict[field] = getattr(domain_application, field).all()

# This will not happen in normal code flow, but having some redundancy doesn't hurt.
# da_dict should not have "id" under any circumstances.
# If it does have it, then this indicates that common_fields is overzealous in the data
# that it is returning. Try looking in DomainHelper.get_common_fields.
if "id" in da_dict:
logger.warning("create_from_da() -> Found attribute 'id' when trying to create")
da_dict.pop("id", None)

# Create a placeholder DomainInformation object
domain_info = DomainInformation(**da_dict)

Expand Down
4 changes: 2 additions & 2 deletions src/registrar/models/utility/domain_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def get_common_fields(model_1: Type[models.Model], model_2: Type[models.Model]):
"""

# Get a list of the existing fields on model_1 and model_2
model_1_fields = set(field.name for field in model_1._meta.get_fields() if field != "id")
model_2_fields = set(field.name for field in model_2._meta.get_fields() if field != "id")
model_1_fields = set(field.name for field in model_1._meta.get_fields() if field.name != "id")
model_2_fields = set(field.name for field in model_2._meta.get_fields() if field.name != "id")

# Get the fields that exist on both DomainApplication and DomainInformation
common_fields = model_1_fields & model_2_fields
Expand Down

0 comments on commit f72e81a

Please sign in to comment.