Skip to content

Commit

Permalink
Merge pull request #2572 from cisagov/dk/979-org-name-address-bug
Browse files Browse the repository at this point in the history
Issue #979: Organization name and mailing address changes not updating log entries
  • Loading branch information
dave-kennedy-ecs authored Aug 14, 2024
2 parents 9a55ade + 8dcaa66 commit 2ebeb14
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/registrar/forms/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,7 @@ def save(self, commit=True):
elif self.is_tribal and not self._field_unchanged("organization_name"):
raise ValueError("organization_name cannot be modified when the generic_org_type is tribal")

else:
super().save()
super().save()

def _field_unchanged(self, field_name) -> bool:
"""
Expand All @@ -552,6 +551,21 @@ def _field_unchanged(self, field_name) -> bool:
"""
old_value = self.initial.get(field_name, None)
new_value = self.cleaned_data.get(field_name, None)

field = self.fields[field_name]

# Check if the field has a queryset attribute before accessing it
if hasattr(field, "queryset") and isinstance(new_value, str):
try:
# Convert the string to the corresponding ID
new_value = field.queryset.get(name=new_value).id
except field.queryset.model.DoesNotExist:
pass # Handle the case where the object does not exist

elif hasattr(new_value, "id"):
# If new_value is a model instance, compare by ID.
new_value = new_value.id

return old_value == new_value


Expand Down

0 comments on commit 2ebeb14

Please sign in to comment.