Problem/Motivation

StringDatabaseStorage::delete() deletes locales_location rows with the condition lid = <source string ID>. In locales_location, lid is the location ID and the string ID is in sid. So deleting a source string deletes the location of another string, and the locations of the deleted string stay.

LocaleConfigManager::getStringNames() finds configuration names through configuration locations. The translate form and the import batch use it, so a string that lost its location no longer updates its configuration translation.

Core does not delete source strings itself. Contributed or custom code does it through the storage API.

Steps to reproduce

  1. Install Drupal with Interface Translation. Add German.
  2. On empty locale tables, create a source string with \Drupal::service('locale.storage')->createString(['source' => 'Example'])->save().
  3. Create the source string of the maintenance message with ->addLocation('configuration', 'system.maintenance')->save(). Its location gets the same ID as the first string.
  4. Delete the first string with $string->delete().
  5. Translate the maintenance message into German at admin/config/regional/translate.
  6. Expected: the German override of system.maintenance has the translation. Actual: it is not updated.

Proposed resolution

Delete the locations with ['sid' => $string->getId()], the same condition deleteStrings() uses.

Remaining tasks

Review.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

AI usage

An LLM helped write the functional test, the steps to reproduce and this summary. The tests were run locally with and without the fix.

Issue fork drupal-3373635

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bgreco created an issue. See original summary.

bgreco’s picture

Status: Active » Needs review

Created an issue fork with a fix for the query and a test.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

@bgreco if you have to open the MR if you want to be reviewed

Tests fail with Failed asserting that actual size 3 matches expected size 0. without the fix.

Think this is good for committer review.

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

I am doing triage on the core RTBC queue.

I read the issue summary and the comments, noting that there is a proposed resolution but no remaining tasks. Also, there are no unanswered questions.

I wonder if there is an existing issue for this. It seems that this is something others would have run into. Maybe it is just me because I don't see a search for duplicates or related issues.

Is it possible to have steps to reproduce?

I read the code and test, which are both straightforward. However, the test is testing the deletion of database rows but it is not a testing the problem stated in the issue summary. I think that needs to be done before string are deleted. I looked in the functional tests in the locale module and there are some related to updates. I did not look closely but I think that should be explored.

I am setting back to needs work for testing.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

mehdi.najeddine made their first commit to this issue’s fork.

mehdi.najeddine’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests

Rebased MR !4362 on main. The fix and the kernel test from @bgreco are unchanged.

Added LocaleTranslationUiTest::testTranslationAfterSourceStringDelete() for the update problem from #5. It creates a source string without a location. Then it creates the maintenance message string with a system.maintenance configuration location. This location gets the same ID as the first string. The test deletes the first string and translates the maintenance message in the UI. Then it checks the German override of system.maintenance.

Without the fix, the override is not updated. With the fix, the test passes.

Core does not delete source strings. PoDatabaseWriter and TranslateEditForm only delete translations. So the steps to reproduce use the storage API. They are now in the issue summary.

I searched the core queue for "locales_location" and found no duplicate.

Generated with the help of an LLM.