Page MenuHomePhabricator

Duplicate entry for key 'cx_translation_ref' in ContentTranslation\Translation::createQuery
Closed, ResolvedPublic4 Estimated Story PointsPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   Wikimedia\Rdbms\DBQueryError: Error 1062: Duplicate entry … for key 'cx_translation_ref'
Function: ContentTranslation\Translation::create
Query: INSERT INTO `cx_translations` (translation_source_title,
exception.trace
from /srv/mediawiki/php-1.39.0-wmf.15/includes/libs/rdbms/database/Database.php(1767)
#0 /srv/mediawiki/php-1.39.0-wmf.15/includes/libs/rdbms/database/Database.php(1751): Wikimedia\Rdbms\Database->getQueryException(string, integer, string, string)
#1 /srv/mediawiki/php-1.39.0-wmf.15/includes/libs/rdbms/database/Database.php(1725): Wikimedia\Rdbms\Database->getQueryExceptionAndLog(string, integer, string, string)
#2 /srv/mediawiki/php-1.39.0-wmf.15/includes/libs/rdbms/database/Database.php(1226): Wikimedia\Rdbms\Database->reportQueryError(string, integer, string, string, boolean)
#3 /srv/mediawiki/php-1.39.0-wmf.15/includes/libs/rdbms/database/Database.php(2274): Wikimedia\Rdbms\Database->query(string, string, integer)
#4 /srv/mediawiki/php-1.39.0-wmf.15/includes/libs/rdbms/database/Database.php(2254): Wikimedia\Rdbms\Database->doInsert(string, array, string)
#5 /srv/mediawiki/php-1.39.0-wmf.15/includes/libs/rdbms/database/DBConnRef.php(68): Wikimedia\Rdbms\Database->insert(string, array, string)
#6 /srv/mediawiki/php-1.39.0-wmf.15/includes/libs/rdbms/database/DBConnRef.php(333): Wikimedia\Rdbms\DBConnRef->__call(string, array)
#7 /srv/mediawiki/php-1.39.0-wmf.15/extensions/ContentTranslation/includes/Translation.php(55): Wikimedia\Rdbms\DBConnRef->insert(string, array, string)
#8 /srv/mediawiki/php-1.39.0-wmf.15/extensions/ContentTranslation/includes/Translation.php(116): ContentTranslation\Translation->create(ContentTranslation\Translator)
#9 /srv/mediawiki/php-1.39.0-wmf.15/extensions/ContentTranslation/includes/ActionApi/ApiContentTranslationSave.php(172): ContentTranslation\Translation->save(ContentTranslation\Translator)
#10 /srv/mediawiki/php-1.39.0-wmf.15/extensions/ContentTranslation/includes/ActionApi/ApiContentTranslationSave.php(95): ContentTranslation\ActionApi\ApiContentTranslationSave->saveTranslation(array, ContentTranslation\Translator)
#11 /srv/mediawiki/php-1.39.0-wmf.15/includes/api/ApiMain.php(1901): ContentTranslation\ActionApi\ApiContentTranslationSave->execute()
#12 /srv/mediawiki/php-1.39.0-wmf.15/includes/api/ApiMain.php(875): ApiMain->executeAction()
#13 /srv/mediawiki/php-1.39.0-wmf.15/includes/api/ApiMain.php(846): ApiMain->executeActionWithErrorHandling()
#14 /srv/mediawiki/php-1.39.0-wmf.15/api.php(90): ApiMain->execute()
#15 /srv/mediawiki/php-1.39.0-wmf.15/api.php(45): wfApiMain()
#16 /srv/mediawiki/w/api.php(3): require(string)
#17 {main}
Impact

Seems to happen about a dozen times a day when attempting to save an edit from Special:ContentTranslation, presumably resulting a generic "Internal server error" in the editor frontend.

Notes

There is another deadlock report for CX about its storage saving function at T256229, which might be related or share a common cause.

Event Timeline

Nikerabbit triaged this task as Medium priority.Aug 1 2022, 11:27 AM
Nikerabbit moved this task from Needs Triage to Bugs on the ContentTranslation board.
UNIQUE INDEX cx_translation_ref (
  translation_source_title, translation_source_language,
  translation_target_language, translation_started_by
),

The refered unique index contains a user id, so this could be a double-click or something which is trying to store the same thing twice over the api (ApiContentTranslationSave)

When the full, non redacted, sql exists, maybe just look if that refered page exists and was created around the time of the exception.

But the backend should handle that nice by giving a conflict warning or ignore the request. The backend already checks if a row exists, but on replica. Maybe a INSERT IGNORE is okay in that case or checking against primary is needed.

brennen subscribed.

Still seeing these in 1.41.0-wmf.27 (T345888).

Change #1137047 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/ContentTranslation@master] TranslationStore: Skip Translation insertion if unique key conflicts

https://gerrit.wikimedia.org/r/1137047

abi_ set the point value for this task to 4.

I've submitted a patch to skip inserting the translation record if the unique key constrict conflicts but since we need the translation id to process the translations, try fetching it from the primary database. If fetching the translation id fails, throw an exception.

In addition, add logging to track how often this happens.

Nikerabbit changed the task status from Open to In Progress.May 12 2025, 7:16 AM

Change #1137047 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] TranslationStore: Skip Translation insertion if unique key conflicts

https://gerrit.wikimedia.org/r/1137047

abi_ moved this task from Need QA to Done on the LPL Essential (LPL Essential 2025 Apr-Jun: CX) board.

Not seeing any occurrences of this since 21st May, 2025. Will continue to monitor.

image.png (1×2 px, 56 KB)

In addition, I'm not seeing this exception message:

Translation save failed: could not insert a new translation or locate an existing one.'

Which means fetching the translation from the primary database is working as expected.

image.png (886×2 px, 101 KB)