Deleting a translation leaves behind orphaned revisions

Created on 10 October 2016, over 7 years ago
Updated 15 May 2024, about 1 month ago

Problem/Motivation

Deleting a translation leaves behind orphaned revisions that can never be retrieved using the UI. The easiest way to describe the problem is to read the steps to reproduce that show the content of the node_field_revision table.

  1. Steps to reproduce:
  2. Install Standard profile in English and enable content_translation module
  3. Add a language (for example French) (admin/config/regional/language)
  4. Enable content translation of article bundles (admin/config/regional/content-language)
  5. Create an English article
    mysql> select nid, vid, langcode from node_field_revision;
    +-----+-----+----------+
    | nid | vid | langcode |
    +-----+-----+----------+
    |   2 |   6 | en       |
    +-----+-----+----------+
    1 row in set (0.00 sec)
    
  6. Edit the edit English article (you now have 2 revisions)
    mysql> select nid, vid, langcode from node_field_revision;
    +-----+-----+----------+
    | nid | vid | langcode |
    +-----+-----+----------+
    |   2 |   6 | en       |
    |   2 |   7 | en       |
    +-----+-----+----------+
    2 rows in set (0.00 sec)
    
  7. Create a French translation
    mysql> select nid, vid, langcode from node_field_revision;
    +-----+-----+----------+
    | nid | vid | langcode |
    +-----+-----+----------+
    |   2 |   8 | fr       |
    |   2 |   6 | en       |
    |   2 |   7 | en       |
    |   2 |   8 | en       |
    +-----+-----+----------+
    4 rows in set (0.01 sec)
    
  8. Edit the English node
    mysql> select nid, vid, langcode from node_field_revision;
    +-----+-----+----------+
    | nid | vid | langcode |
    +-----+-----+----------+
    |   2 |   8 | fr       |
    |   2 |   9 | fr       |
    |   2 |   6 | en       |
    |   2 |   7 | en       |
    |   2 |   8 | en       |
    |   2 |   9 | en       |
    +-----+-----+----------+
    6 rows in set (0.00 sec)
    
  9. Delete the French translation
    mysql> select nid, vid, langcode from node_field_revision;
    +-----+-----+----------+
    | nid | vid | langcode |
    +-----+-----+----------+
    |   2 |   8 | fr       |
    |   2 |   6 | en       |
    |   2 |   7 | en       |
    |   2 |   8 | en       |
    |   2 |   9 | en       |
    +-----+-----+----------+
    5 rows in set (0.00 sec)
    
  10. At this point:
    • although we have a row for a French translation the node is showing as untranslated on node/2/translations
    • And on the revisions tab you can only revert to revision 6 & 7.
  11. Hacking the URL to revert to revision 8... does magic and the french translation appears again...
    mysql> select nid, vid, langcode from node_field_revision;
    +-----+-----+----------+
    | nid | vid | langcode |
    +-----+-----+----------+
    |   2 |   8 | fr       |
    |   2 |  10 | fr       |
    |   2 |   6 | en       |
    |   2 |   7 | en       |
    |   2 |   8 | en       |
    |   2 |   9 | en       |
    |   2 |  10 | en       |
    +-----+-----+----------+
    7 rows in set (0.00 sec)
    

We need decide what the expected behaviour should be. i don't think deleting the current translation revision is the expected behaviour. It is a halfway house between removing all revisions that pertain to the translation and just creating a new revision without the translation.

Discovered whilst working on πŸ› Deleting an entity with revisions and file/image field does not release file usage of non-default revisions, causing files to linger Postponed .

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated less than a minute ago

Created by

πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Did not test

    But for tests requested in #7

  • πŸ‡ΈπŸ‡ͺSweden marcusml

    This makes it more difficult for sites to comply with GDPR as it can be difficult to remove unlawful personal data.

    Well this depends on how you look at it. If we consider revisions as a backup, then everything is fine. We only have to ensure that the revisions cannot be accessed. If you still want to delete a specific translation from all revisions, then this is still possible even with the current issue:

    $entity_type_id = 'xyz';
    $entity_id = 1092;
    $remove_translation_langcode = 'abc';
    $entity_type_manager = \Drupal::entityTypeManager();
    $entity_type = $entity_type_manager->getDefinition($entity_type_id);
    $storage = $entity_type_manager->getStorage($entity_type_id);
    $revisions = $storage->getQuery()
      ->condition($entity_type->getKey('id'), $entity_id)
      ->condition($entity_type->getKey('langcode'), $remove_translation_langcode)
      ->allRevisions()
      ->execute();
    foreach (array_keys($revisions) as $revision_id) {
      $revision = $storage->loadRevision($revision_id);
      $revision->removeTranslation($remove_translation_langcode);
      $revision->save();
    } 
    

    This doesn't seem to be true (anymore at least). I'm currently trying to clean up translations from old revisions. Removing a translation from a revision and calling save() on it results in a new revision being created with the translation removed. Instead of the translation being removed from the loaded revision.

    I haven't yet found a way in which the Entity API allows me to remove a translation from a revision. Setting $revision->setNewRevision(FALSE); doesn't make it work either.

  • πŸ‡ͺπŸ‡ΈSpain facine

    @marcusml, you need to set syncing flag to TRUE or a new revision will be created.

    https://www.drupal.org/project/drupal/issues/2803717#comment-13080838 β†’

  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦
Production build 0.69.0 2024