Website Encounter Error when translating the forum.

Created on 18 September 2024, about 2 months ago
Updated 20 September 2024, about 2 months ago

Problem/Motivation

We have been using Drupal 10.2.7. we have created the new content (EN Language is the default) and published the content. the content was created and a new record has been stored in the Database. Nid and Tid columns are primary keys in 10.2.7.

We translated the content and published the content. The content was not published and the "A website encounter error message" was displayed. Please refer to the error message below.

Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '22757-237' for key 'PRIMARY': INSERT INTO "forum_index" ("nid", "title", "tid", "sticky", "created", "comment_count", "last_comment_timestamp") 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), (:db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13); Array ( [:db_insert_placeholder_0] => 22757 [:db_insert_placeholder_1] => Sep182 [:db_insert_placeholder_2] => 237 [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => 1726663812 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 1726663812 [:db_insert_placeholder_7] => 22757 [:db_insert_placeholder_8] => Sep182 [:db_insert_placeholder_9] => 237 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1726663812 [:db_insert_placeholder_12] => 0 [:db_insert_placeholder_13] => 1726663812 ) in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 45 of /code/web/core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php).

Steps to reproduce

  • Configure Multilingual and enable two languages.
  • Create new forum content and publish it.
  • Translate and publish it. getting a Website Encounter Error.

Proposed resolution

When translating the forum. It should not break the site.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

2.0

Component

forum.module

Created by

🇮🇳India Logeshvaran

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

Comments & Activities

  • Issue created by @Logeshvaran
  • The forum module is leaving Drupal core. I am moving this issue to the contributed project with the others.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    I think we either need to add langcode to the index table or skip inserting for the non-default translation

  • 🇮🇳India Logeshvaran

    @larowlan, Thanks for your reply. Can we follow the schema structure ( Remove the Primary key for NID and TID ) like Drupal 9 (forum_index), which allows the same NID and TID based on the site's available languages? Will it impact the site if we remove the primary key? Please suggest.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Yes it will prevent use of read committed at the db layer

    I think adding the langcode feels like the best approach

  • 🇬🇧United Kingdom Jons

    I've hit a similar problem and it's just when trying to set the Promoted flag in HOOK_node_insert()
    Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '897' for key 'forum.PRIMARY': INSERT INTO "forum" ("tid", "vid", "nid") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 59 [:db_insert_placeholder_1] => 897 [:db_insert_placeholder_2] => 124 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

    So this is into the main forum table rather than the index.
    It could be because I'm calling save() on the node and that triggers forum's presave or insert hooks.
    I have to call save() as the hook is downstream of DB update.
    I also did a separate load/update/save of the node (after trying just saving the passed-in node) - same result.
    Looking at the forum table the current highest vid is 896, ie no 897 present. The insert fails so both attempts to write the record presumably get thrown away.
    Node revisions are switched off for this content type.
    Trying to catch (and ignore) the exception does not work.

    Suggest duplicate keys allowed?

  • 🇬🇧United Kingdom Jons

    Resolution of #6 seems to be to change src/ForumIndexStorage.php by adding a check for an existing record in create() and createIndex() and skipping insert if one does exist. A possible patch is attached

Production build 0.71.5 2024