Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate key issue in PublicContact #3307

Open
2 tasks
dave-kennedy-ecs opened this issue Jan 7, 2025 · 0 comments · May be fixed by #3362
Open
2 tasks

Duplicate key issue in PublicContact #3307

dave-kennedy-ecs opened this issue Jan 7, 2025 · 0 comments · May be fixed by #3362
Assignees
Labels
bug Something that isn't working as intended dev issue is for the dev team

Comments

@dave-kennedy-ecs
Copy link
Contributor

dave-kennedy-ecs commented Jan 7, 2025

Duplicate key issues in database for PublicContact in stable.

Instances of bug in logs:
Dec 26, 2024 @ 18:38:13.547 /domain/12821
Jan 6, 2025 @ 08:06:14.790 /domain/13059

Stack trace for reference:

Traceback (most recent call last):
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "registrar_publiccontact_contact_type_registry_id_4542e191_uniq"
DETAIL:  Key (contact_type, registry_id, domain_id)=(admin, MoTa5H3fL5PI5Ub3, 13059) already exists.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/vcap/deps/0/python/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/contrib/auth/mixins.py", line 109, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/vcap/app/registrar/views/domain.py", line 81, in get
    context = self.get_context_data(object=self.object)
  File "/home/vcap/app/registrar/views/domain.py", line 268, in get_context_data
    security_email = self.object.get_security_email()
  File "/home/vcap/app/registrar/models/domain.py", line 1004, in get_security_email
    security_contact = self.generic_contact_getter(security)
  File "/home/vcap/app/registrar/models/domain.py", line 1289, in generic_contact_getter
    contacts = self._get_property(desired_property)
  File "/home/vcap/app/registrar/models/domain.py", line 2128, in _get_property
    self._fetch_cache(
  File "/home/vcap/app/registrar/models/domain.py", line 1882, in _fetch_cache
    self._update_hosts_and_contacts(cleaned, fetch_hosts, fetch_contacts)
  File "/home/vcap/app/registrar/models/domain.py", line 1945, in _update_hosts_and_contacts
    cleaned["contacts"] = self._get_contacts(cleaned.get("_contacts", []))
  File "/home/vcap/app/registrar/models/domain.py", line 2050, in _get_contacts
    cleaned_contacts = self._fetch_contacts(contacts)
  File "/home/vcap/app/registrar/models/domain.py", line 1668, in _fetch_contacts
    in_db = self._get_or_create_public_contact(mapped_object)
  File "/home/vcap/app/registrar/models/domain.py", line 2089, in _get_or_create_public_contact
    public_contact.save(skip_epp_save=True)
  File "/home/vcap/app/registrar/models/public_contact.py", line 53, in save
    super().save(*args, **kwargs)
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/models/base.py", line 814, in save
    self.save_base(
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/models/base.py", line 877, in save_base
    updated = self._save_table(
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/models/base.py", line 1020, in _save_table
    results = self._do_insert(
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/models/base.py", line 1061, in _do_insert
    return manager._insert(
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/models/query.py", line 1805, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
    cursor.execute(sql, params)
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/vcap/deps/0/python/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "registrar_publiccontact_contact_type_registry_id_4542e191_uniq"
DETAIL:  Key (contact_type, registry_id, domain_id)=(admin, MoTa5H3fL5PI5Ub3, 13059) already exists.

AC

  • investigate this bug (see the slack thread for more context and the logs in kibana)
  • determine the cause of the bug and implement a fix

Additional details

We have had this issue pop up a few times before, so I think the issue is coming from our PublicContact model, I would evaluate this model and it's relation with domain.py as part of this investigation. A refactor may be needed.

slack thread with more context on this bug

@dave-kennedy-ecs dave-kennedy-ecs converted this from a draft issue Jan 7, 2025
@dave-kennedy-ecs dave-kennedy-ecs added the bug Something that isn't working as intended label Jan 7, 2025
@abroddrick abroddrick moved this from 👶 New to 🎯 Ready in .gov Product Board Jan 9, 2025
@abroddrick abroddrick added the dev issue is for the dev team label Jan 9, 2025
@zandercymatics zandercymatics self-assigned this Jan 13, 2025
@zandercymatics zandercymatics moved this from 🎯 Ready to 🏗 In progress in .gov Product Board Jan 14, 2025
@zandercymatics zandercymatics linked a pull request Jan 17, 2025 that will close this issue
32 tasks
@zandercymatics zandercymatics moved this from 🏗 In progress to 👀 In review in .gov Product Board Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working as intended dev issue is for the dev team
Projects
Status: 👀 In review
Development

Successfully merging a pull request may close this issue.

3 participants