mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-27 21:16:28 +02:00
PR suggestions
This commit is contained in:
parent
86717945de
commit
cb5d9d2368
1 changed files with 4 additions and 11 deletions
|
@ -846,7 +846,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
|
|
||||||
# get publicContact objects that have the matching
|
# get publicContact objects that have the matching
|
||||||
# domain and type but a different id
|
# domain and type but a different id
|
||||||
# like in highlander we there can only be one
|
# like in highlander where there can only be one
|
||||||
duplicate_contacts = PublicContact.objects.exclude(registry_id=contact.registry_id).filter(
|
duplicate_contacts = PublicContact.objects.exclude(registry_id=contact.registry_id).filter(
|
||||||
domain=self, contact_type=contact.contact_type
|
domain=self, contact_type=contact.contact_type
|
||||||
)
|
)
|
||||||
|
@ -1962,20 +1962,13 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
domain=self,
|
domain=self,
|
||||||
)
|
)
|
||||||
|
|
||||||
# If we find duplicates, log it and delete the newest ones.
|
# If we find duplicates, log it and delete the oldest ones.
|
||||||
if db_contact.count() > 1:
|
if db_contact.count() > 1:
|
||||||
logger.warning("_get_or_create_public_contact() -> Duplicate contacts found. Deleting duplicate.")
|
logger.warning("_get_or_create_public_contact() -> Duplicate contacts found. Deleting duplicate.")
|
||||||
|
|
||||||
# Q: Should we be deleting the newest or the oldest? Does it even matter?
|
newest_duplicate = db_contact.order_by("-created_at").first()
|
||||||
oldest_duplicate = db_contact.order_by("created_at").first()
|
|
||||||
|
|
||||||
# The linter wants this check on the id / oldest_duplicate, though in practice
|
duplicates_to_delete = db_contact.exclude(id=newest_duplicate.id) # type: ignore
|
||||||
# this should be otherwise impossible.
|
|
||||||
if oldest_duplicate is not None and hasattr(oldest_duplicate, "id"):
|
|
||||||
# Exclude the oldest
|
|
||||||
duplicates_to_delete = db_contact.exclude(id=oldest_duplicate.id)
|
|
||||||
else:
|
|
||||||
duplicates_to_delete = db_contact
|
|
||||||
|
|
||||||
# Delete all duplicates
|
# Delete all duplicates
|
||||||
duplicates_to_delete.delete()
|
duplicates_to_delete.delete()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue