Inconsistent database because of a bug in the Content Moderation module

Created on 18 October 2019, almost 6 years ago
Updated 23 February 2023, over 2 years ago

Creating translations of published nodes results a faulty db state, which makes impossible of the listing of some node content in content revision views. To reproduce this issue the minimum setup:

- Installed a brand new Drupal 8.7.8, with views, moderation and workflow modules enabled
- Added a new language the system (/admin/config/regional/language) - Hungarian
- Created a new translatable content type - testbundle
- Created a new simple workflow, with only the "Draft" and "Published" moderation states, and it was applied to the "testbundle" type
- Created a new view based on the "Content revision", where all node revisions are listed (deleted the Published content filter)

If you create a new node in "Draft"t version, and add a new translation to this node, everything works fine, all node revisions will be listed in the testview, and you can also execute the workflow. However, if you create a new node as "Published", and add the translation to it as "Draft", the view will only list the original language node revisions, and it is because in this case adding the translation do not add a new value to the node_field_data table. If you add translation to the "Draft" version of the node, the node_field_data table will contain 2 items for the same nid (in this case it will be an English and a Hungarian one). If you add translationto the "Published" version, only the English version will be present.

Expected results: listing the node revisions of a translated node will show all revisions in all available languages (as many items as in the node_field_revision table)

Happened instead: depending on the order of publishing/translating, some revisions cannot be listed.

I will attach the config of my test-setup to this bug-report (config.zip).

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
Content moderationΒ  β†’

Last updated 2 days ago

  • Maintained by
  • πŸ‡¦πŸ‡ΊAustralia @Sam152
Created by

πŸ‡­πŸ‡ΊHungary zolt_toth

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • fathima.asmat London, UK

    Patch 6 works for new translations but does not affect existing draft translation that should be treated as default revision when there isn't a published translation. So we may need something like:

          // Check if any of the translation revision has a published version,
          // otherwise set the latest translation to default revision.
          if (!$update_default_revision && $entity instanceof TranslatableInterface && $entity instanceof RevisionableInterface) {
            $update_default_revision = $entity->isNewTranslation();
            if (!$update_default_revision) {
              $update_default_translation_revision = FALSE;
              $published_translation_revision = FALSE;
              $langcode = $this->languageManager->getCurrentLanguage()->getId();
              $storage = $this->entityTypeManager
                ->getStorage($entity->getEntityTypeId());
              $revision_ids = $storage->revisionIds($entity);
              if ($revision_ids) {
                foreach ($revision_ids as $revision_id) {
                  $revision = $storage->loadRevision($revision_id);
                  if ($revision->hasTranslation($langcode) && ($translation = $revision->getTranslation($langcode)) && $translation->isRevisionTranslationAffected()) {
                    if ($workflow->getTypePlugin()
                      ->getState($translation->moderation_state->value)
                      ->isPublishedState()) {
                      $published_translation_revision = TRUE;
                      break;
                    }
                  }
                }
              }
    
              if (!$published_translation_revision && $entity->hasTranslation($langcode) && $translation = $entity->getTranslation($langcode)) {
                $update_default_translation_revision = !($workflow->getTypePlugin()
                  ->getState($translation->moderation_state->value)
                  ->isPublishedState());
              }
    
              $update_default_revision = $update_default_translation_revision;
            }
          }
    

    Patch attached.

  • Status changed to Needs review over 2 years ago
  • Status changed to Needs work over 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States dabblela

    Agreed with @fathima.asmat, this definitely needs a way to update the default revision of a translation that has never been published. I think it can be done with this code, but I'm a little wary of potentially looping through every revision of a node so I took a different approach.

    I was able to fix the issue here by:
    1) applying the patch from πŸ› New translations for moderated nodes are not created in the initial workflow state Needs work
    2) setting the default moderation state to "Default moderation state" and
    3) creating a new state called "Pre-published" with "Default revision" enabled

    This approach has worked better in testing with modules that use `hasTranslationChanges` (eg, paragraphs), I think because the default revision field is set earlier in the entity save process.

  • πŸ‡­πŸ‡ΊHungary mibfire

    https://www.drupal.org/project/drupal/issues/3088790#comment-14937914 πŸ› Inconsistent database because of a bug in the Content Moderation module Needs work

    This patch doesn't work in the following case:

    • Content moderation with https://www.drupal.org/files/issues/2023-02-23/content-moderation-unpubl... β†’ and moderation/translation enabled on a content type.
    • Enable Croatian language.
    • Create a Draft node in Croatian.
    • Translate this node to English(Draft).
    • Submit the Croatian translation into Published state.
    • Submit the Croatian translation into Unpublished state.
    • Check the node view page of Croatian translation where the "Latest version" tab should be visible(but it is not because the default revision is always the last revision).

    However this scenario works with https://www.drupal.org/files/issues/2020-06-09/3088790-10.patch β†’ and https://www.drupal.org/project/drupal/issues/3329066#comment-14962117 πŸ› Creating a new translation may delete translations with drafts Fixed patches. Plus this works with https://www.drupal.org/project/drupal/issues/3088790#comment-14839675 πŸ› Inconsistent database because of a bug in the Content Moderation module Needs work too.

  • πŸ‡ΊπŸ‡¦Ukraine v.dovhaliuk

    A new patch resolves an issue if Content Moderation is enabled for the Taxonomy, and $revision_ids = $storage->revisionIds($entity); throws an error undefined method <code>revisionIds()

  • First commit to issue fork.
  • Pipeline finished with Failed
    15 days ago
    Total: 668s
    #574340
  • Pipeline finished with Failed
    15 days ago
    #574346
  • Pipeline finished with Failed
    15 days ago
    Total: 711s
    #574518
  • Pipeline finished with Failed
    14 days ago
    Total: 729s
    #574743
  • Pipeline finished with Failed
    14 days ago
    Total: 701s
    #575018
  • πŸ‡¦πŸ‡ΊAustralia thomwilhelm Sydney

    OK so I ran into this issue recently, clearly translations + content moderation is a very complicated subject in Drupal, but I thought it would just be worth doing a bit of research into why this happens now.

    So I'm working on a site that uses translations + the old workbench moderation module, and have been looking into migrating to content moderation. Everything went pretty well, but some of our internal Functional tests were broken in a strange way. Namely the following case (basically comment #16 on this ticket):

    1. Create a published version of an English page.
    2. Create a draft version of that page in Japanese.

    Now when you go to any view that relies on node_field_data, the Japanese version of the page isn't there. In our case this mean it wasn't appearing on both /admin/content and a custom view we'd built to show pages that were "Draft content".

    I started digging into whether this was an issue on Vanilla Drupal 11 and I found that is it. The draft version of the Japanese page doesn't appear at all on /admin/content, and while it does appear on the view of moderated content /admin/content/moderated, it's Content type field is empty.

    Basically a new entity will be saved as the default revision (even being created in draft), but a new translation will not. This is due to the logic that's in content_moderation/src/EntityOperations::preSave:

    $update_default_revision = $entity->isNew()
      || $current_state->isDefaultRevisionState()
      || !$this->moderationInfo->isDefaultRevisionPublished($entity);

    If you review isDefaultRevisionPublished, in content moderation this returns true if any of the translations are published (which in this case, the English translation is published) so this returns TRUE. Whereas in workbench moderation it was only checking if the translation language was published (which in this case would have been Japanese) so this returns FALSE.

    As content moderation forked workbench moderation, you can see this behaviour diverged in core here: https://www.drupal.org/project/drupal/issues/2862988 β†’

    In that issue, if you read comment #13 and #14 you can see basically the same issue we are experiencing now was discovered, and the following fix was added:

           $update_default_revision = $entity->isNew()
    +        || $entity->isNewTranslation()
             || $current_state->isDefaultRevisionState()
             || !$this->isDefaultRevisionPublished($entity, $workflow);

    Which is interesting as that's basically the same logic this issue has landed on. So when this this get removed?

    This $entity->isNewTranslation() line was then removed as part of the following issue: https://www.drupal.org/project/drupal/issues/2860097 β†’

    To try and move this forward, I've rebased the MR created by @EduardoMoralesAlberti onto a new MR targeting Drupal 11.x, added some extra test cases to the Content type label not appearing in the moderated content view, and made an attempt to fix up any behaviour that this changes (note: it's still marked as failing, but I believe that's due to unrelated issues in CI).

    I'd welcome any feedback from anyone more familiar with translations / content moderation.

  • πŸ‡¦πŸ‡ΊAustralia thomwilhelm Sydney
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Haven't reviewed yet but issue summary should follow the standard template please. Current steps are saying install Drupal 8.7.8 so definitely out of date.

    Thanks!

Production build 0.71.5 2024