department-of-veterans-affairs / va.gov-cms

Editor-centered management for Veteran-centered content.
https://prod.cms.va.gov
GNU General Public License v2.0
97 stars 69 forks source link

EntityStorageException: Duplicate entry inserting new media entities. #8593

Open ndouglas opened 2 years ago

ndouglas commented 2 years ago

Describe the defect

See this Sentry issue.

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'ac406ae5-7027-4c75-b578-07f98c1a4553' for key 'media_field__uuid__value': INSERT INTO "media" ("vid", "bundle", "uuid", "langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
    [:db_insert_placeholder_0] => 
    [:db_insert_placeholder_1] => image
    [:db_insert_placeholder_2] => ac406ae5-7027-4c75-b578-07f98c1a4553
    [:db_insert_placeholder_3] => en
)
 in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 811 of /var/www/cms/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

This appears to happen with some regularity. It might happen every time a media entry is inserted with certain characteristics, e.g. from a certain interface; given that some entities are saved multiple times upon insert because of other issues, this might be a side effect of a hook or other bit of some code somewhere.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here. Reach out to the Product Managers to determine if it should be escalated as critical (prevents users from accomplishing their work with no known workaround and needs to be addressed within 2 business days).

Desktop (please complete the following information if relevant, or delete)

Labels

(You can delete this section once it's complete)

CMS Team

Please check the team(s) that will do this work.

swirtSJW commented 2 years ago

I found an example in watchdog that gives some more specifics

<table class="dblog-event" data-striping="1" style="width: 4810.76px; margin-top: var(--space-l); margin-bottom: var(--space-l); border-collapse: collapse;"><tbody><tr class="odd" style="border-bottom: 0.0625rem solid var(--color-gray-200); color: var(--color-text); background: var(--color-white);"><th style="position: relative; box-sizing: border-box; height: var(--space-xl); padding: var(--space-xs) var(--space-m); text-align: left; color: var(--color-text); background: var(--color-gray-050); line-height: 1.25rem;">Type</th><td style="box-sizing: border-box; height: 4rem; padding: var(--space-xs) var(--space-m); text-align: left;">media</td></tr><tr class="even" style="border-bottom: 0.0625rem solid var(--color-gray-200); color: var(--color-text); background: var(--color-white);"><th style="position: relative; box-sizing: border-box; height: var(--space-xl); padding: var(--space-xs) var(--space-m); text-align: left; color: var(--color-text); background: var(--color-gray-050); line-height: 1.25rem;">Date</th><td style="box-sizing: border-box; height: 4rem; padding: var(--space-xs) var(--space-m); text-align: left;">Tuesday, April 5, 2022 - 10:17 am</td></tr><tr class="odd" style="border-bottom: 0.0625rem solid var(--color-gray-200); color: var(--color-text); background: var(--color-white);"><th style="position: relative; box-sizing: border-box; height: var(--space-xl); padding: var(--space-xs) var(--space-m); text-align: left; color: var(--color-text); background: var(--color-gray-050); line-height: 1.25rem;">User</th><td style="box-sizing: border-box; height: 4rem; padding: var(--space-xs) var(--space-m); text-align: left;"><a title="View user profile." href="https://prod.cms.va.gov/user/3633" lang="" about="/user/3633" typeof="schema:Person" property="schema:name" datatype="" class="username" style="background-color: transparent; color: var(--color-link);">Jesus.Perez2@va.gov</a></td></tr><tr class="even" style="border-bottom: 0.0625rem solid var(--color-gray-200); color: var(--color-text); background: var(--color-white);"><th style="position: relative; box-sizing: border-box; height: var(--space-xl); padding: var(--space-xs) var(--space-m); text-align: left; color: var(--color-text); background: var(--color-gray-050); line-height: 1.25rem;">Location</th><td style="box-sizing: border-box; height: 4rem; padding: var(--space-xs) var(--space-m); text-align: left;"><a href="https://prod.cms.va.gov/media-library?_wrapper_format=drupal_ajax&amp;ajax_form=1&amp;hash=UjmpFQWlIq7W73Yl9bZYmThZGt2FvmmQQUAr2bQ0ZZM&amp;media_library_allowed_types%5Bimage%5D=image&amp;media_library_opener_id=media_library.opener.field_widget&amp;media_library_opener_parameters%5Bfield_widget_id%5D=field_media&amp;media_library_opener_parameters%5Bentity_type_id%5D=node&amp;media_library_opener_parameters%5Bbundle%5D=vet_center_cap&amp;media_library_opener_parameters%5Bfield_name%5D=field_media&amp;media_library_opener_parameters%5Bentity_id%5D=43281&amp;media_library_opener_parameters%5Brevision_id%5D=611149&amp;media_library_remaining=1&amp;media_library_selected_type=image" style="background-color: transparent; color: var(--color-link);">https://prod.cms.va.gov/media-library?_wrapper_format=drupal_ajax&amp;ajax_form=1&amp;hash=UjmpFQWlIq7W73Yl9bZYmThZGt2FvmmQQUAr2bQ0ZZM&amp;media_library_allowed_types%5Bimage%5D=image&amp;media_library_opener_id=media_library.opener.field_widget&amp;media_library_opener_parameters%5Bfield_widget_id%5D=field_media&amp;media_library_opener_parameters%5Bentity_type_id%5D=node&amp;media_library_opener_parameters%5Bbundle%5D=vet_center_cap&amp;media_library_opener_parameters%5Bfield_name%5D=field_media&amp;media_library_opener_parameters%5Bentity_id%5D=43281&amp;media_library_opener_parameters%5Brevision_id%5D=611149&amp;media_library_remaining=1&amp;media_library_selected_type=image</a></td></tr><tr class="odd" style="border-bottom: 0.0625rem solid var(--color-gray-200); color: var(--color-text); background: var(--color-white);"><th style="position: relative; box-sizing: border-box; height: var(--space-xl); padding: var(--space-xs) var(--space-m); text-align: left; color: var(--color-text); background: var(--color-gray-050); line-height: 1.25rem;">Referrer</th><td style="box-sizing: border-box; height: 4rem; padding: var(--space-xs) var(--space-m); text-align: left;"><a href="https://prod.cms.va.gov/node/43281/edit?destination=/section/vha/vet-centers/houston-west-vet-center" style="background-color: transparent; color: var(--color-link);">https://prod.cms.va.gov/node/43281/edit?destination=/section/vha/vet-centers/houston-west-vet-center</a></td></tr><tr class="even" style="border-bottom: 0.0625rem solid var(--color-gray-200); color: var(--color-text); background: var(--color-white);"><th style="position: relative; box-sizing: border-box; height: var(--space-xl); padding: var(--space-xs) var(--space-m); text-align: left; color: var(--color-text); background: var(--color-gray-050); line-height: 1.25rem;">Message</th><td style="box-sizing: border-box; height: 4rem; padding: var(--space-xs) var(--space-m); text-align: left;"><em class="placeholder">Drupal\Core\Database\IntegrityConstraintViolationException</em>: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'ac406ae5-7027-4c75-b578-07f98c1a4553' for key 'media_field__uuid__value': INSERT INTO "media" ("vid", "bundle", "uuid", "langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] =&gt; [:db_insert_placeholder_1] =&gt; image [:db_insert_placeholder_2] =&gt; ac406ae5-7027-4c75-b578-07f98c1a4553 [:db_insert_placeholder_3] =&gt; en ) in<span> </span><em class="placeholder">Drupal\Core\Database\Driver\mysql\ExceptionHandler-&gt;handleExecutionException()</em><span> </span>(line<span> </span><em class="placeholder">50</em><span> </span>of<span> </span><em class="placeholder">/var/www/cms/docroot/core/lib/Drupal/Core/Database/Driver/mysql/ExceptionHandler.php</em>).</td></tr><tr class="odd" style="border-bottom: 0.0625rem solid var(--color-gray-200); color: var(--color-text); background: var(--color-white);"><th style="position: relative; box-sizing: border-box; height: var(--space-xl); padding: var(--space-xs) var(--space-m); text-align: left; color: var(--color-text); background: var(--color-gray-050); line-height: 1.25rem;">Severity</th><td style="box-sizing: border-box; height: 4rem; padding: var(--space-xs) var(--space-m); text-align: left;">Error</td></tr><tr class="even" style="border-bottom: 0.0625rem solid var(--color-gray-200); color: var(--color-text); background: var(--color-white);"><th style="position: relative; box-sizing: border-box; height: var(--space-xl); padding: var(--space-xs) var(--space-m); text-align: left; color: var(--color-text); background: var(--color-gray-050); line-height: 1.25rem;">Hostname</th><td style="box-sizing: border-box; height: 4rem; padding: var(--space-xs) var(--space-m); text-align: left;">10.247.32.190</td></tr><tr class="odd" style="border-bottom: 0.0625rem solid var(--color-gray-200); color: var(--color-text); background: var(--color-bgblue-hover);"><th style="position: relative; box-sizing: border-box; height: var(--space-xl); padding: var(--space-xs) var(--space-m); text-align: left; color: rgb(33, 33, 33); background: var(--color-gray-050); line-height: 1.25rem; font-family: &quot;Source Sans Pro&quot;, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Operations</th><br class="Apple-interchange-newline">Type    media
Date    Tuesday, April 5, 2022 - 10:17 am
User    [Jesus.Perez2@va.gov](https://prod.cms.va.gov/user/3633)
Location    https://prod.cms.va.gov/media-library?_wrapper_format=drupal_ajax&ajax_form=1&hash=UjmpFQWlIq7W73Yl9bZYmThZGt2FvmmQQUAr2bQ0ZZM&media_library_allowed_types%5Bimage%5D=image&media_library_opener_id=media_library.opener.field_widget&media_library_opener_parameters%5Bfield_widget_id%5D=field_media&media_library_opener_parameters%5Bentity_type_id%5D=node&media_library_opener_parameters%5Bbundle%5D=vet_center_cap&media_library_opener_parameters%5Bfield_name%5D=field_media&media_library_opener_parameters%5Bentity_id%5D=43281&media_library_opener_parameters%5Brevision_id%5D=611149&media_library_remaining=1&media_library_selected_type=image
Referrer    https://prod.cms.va.gov/node/43281/edit?destination=/section/vha/vet-centers/houston-west-vet-center
Message Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'ac406ae5-7027-4c75-b578-07f98c1a4553' for key 'media_field__uuid__value': INSERT INTO "media" ("vid", "bundle", "uuid", "langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => image [:db_insert_placeholder_2] => ac406ae5-7027-4c75-b578-07f98c1a4553 [:db_insert_placeholder_3] => en ) in Drupal\Core\Database\Driver\mysql\ExceptionHandler->handleExecutionException() (line 50 of /var/www/cms/docroot/core/lib/Drupal/Core/Database/Driver/mysql/ExceptionHandler.php).
Severity    Error
Hostname    10.247.32.190
Operations
swirtSJW commented 2 years ago

Clicking the top link in the watchdog for location brings to this. image

Looks like maybe ajax call is happening twice. One possibility is a user being double-clicky when they should be single clicky and the action link not properly preventing the double click.

If it was systemic I would think there would be more of them.