Errors on inserting duplicate entries into acquia_contenthub_publisher_export_tracking table

Created on 16 August 2019, over 5 years ago
Updated 19 January 2023, about 2 years ago

We have some custom code that updates an existing file in certain circumstances. Our custom code runs this fairly normal Drupal code:

$file = file_save_data($content, $uri, FILE_EXISTS_REPLACE);

When this gets run the first time, a record for the file is added to acquia_contenthub_publisher's acquia_contenthub_publisher_export_tracking table. The second time this runs, the acquia_contenthub_module throws an SQL error:

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Core\Entity\EntityStorageException</em>: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry &#039;file-376&#039; for key &#039;entity&#039;: INSERT INTO {acquia_contenthub_publisher_export_tracking} (entity_type, entity_id, entity_uuid, status, created, modified, hash) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array
(
    [:db_insert_placeholder_0] =&gt; file
    [:db_insert_placeholder_1] =&gt; 376
    [:db_insert_placeholder_2] =&gt; 4320e516-22a7-49f1-8fe3-2b45c1fb5933
    [:db_insert_placeholder_3] =&gt; queued
    [:db_insert_placeholder_4] =&gt; 2019-08-14T14:04:25-05:00
    [:db_insert_placeholder_5] =&gt; 2019-08-14T14:04:25-05:00
    [:db_insert_placeholder_6] =&gt; 
)
 in <em class="placeholder">Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save()</em> (line <em class="placeholder">783</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php</em>).

The acquia_contenthub_publisher module reacts to the file_save_data() call as if a new file is being created each time each time, resulting in the above SQL error.

I'm attaching a patch that fixes the issue by merging rather than inserting when adding entries to the tracking table.

πŸ› Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States becw

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024