Drupal 10, the latest version of the open-source digital experience platform with even more features, is here.Problem/Motivation
The relationship that joins the node revision table to the base table fails to ensure the correct language is joined. This can be reproduced in content moderation by:
- Adding two languages.
- Creating a draft item of content and translating it.
- On the "Moderated content" tab, two entires will be displayed.
Proposed resolution
Fix the views data to add langcode as additional criteria for the join.
Remaining tasks
User interface changes
API changes
Data model changes











Comments
Comment #1
matoeil CreditAttribution: matoeil commentedmatoeil created an issue.
the is the request:
SELECT node_field_revision.langcode AS node_field_revision_langcode, node_field_data_node_field_revision.langcode AS node_field_data_node_field_revision_langcode, users_field_data_node_field_revision.langcode AS users_field_data_node_field_revision_langcode, node_field_revision.vid AS vid, node_field_data_node_field_revision.nid AS node_field_data_node_field_revision_nid, users_field_data_node_field_revision.uid AS users_field_data_node_field_revision_uid
FROM
node_field_revision node_field_revision
LEFT JOIN node_field_data node_field_data_node_field_revision ON node_field_revision.nid = node_field_data_node_field_revision.nid
LEFT JOIN users_field_data users_field_data_node_field_revision ON node_field_revision.uid = users_field_data_node_field_revision.uid
LEFT JOIN node_field_revision node_field_revision2 ON node_field_revision.nid = node_field_revision2.nid AND node_field_revision2.vid > node_field_revision.vid
WHERE node_field_revision2.nid IS NULL
ORDER BY node_field_revision.changed DESC
LIMIT 50 OFFSET 0
it shows that the duplicate have the same correct node_field_revision_langcode but a different node_field_data_node_field_revision_langcode
Comment #2
timmillwoodIt'd be great to get a test to recreate this bug.
Comment #4
leisurman CreditAttribution: leisurman commentedI am seeing duplicates too. See screenshot here
To recreate this:
I installed a plain Lightning site (lightning-8.x-3.103) Use the 3 core moderation modules that are enabled by default now in Lightning: Content Moderation, Workflows, Lightning Workflow, and Scheduler. Make sure Page content type is enabled as a workflow in /admin/config/workflow/workflows.
enable pathauto and add the pattern [node:title] for Page content type.
Create a page, then published it.
I enabled all 4 core translation modules:
Configuration Translation
Content Translation
Interface Translation
Language
I added the Spanish language.
I went to the first node and added a translated version of it.
And saved it as a draft. I went to "Moderated Content" and I
see 1 item. The translated version. I go to content overview
and I see 1 item, the original english version. Now I publish
the translated version. There are no items in "Moderated
Content" and 2 items in Content Overview. The original english
version and the traslated version. From the Content Overview
page I can access both versions and edit them. The revisions
are correct for both versions. I have more revisions for the
original english version. This all looks correct and better
then the 5 duplicates I get using the Workbench module.
The problem:
If I create a new draft of the ordinal english node or the translated version then go to:
"Moderated Content" /admin/content/moderated
I now see 2 items of that node they are duplicates. See screenshot here
Another issue I found. If I go to the translated version my url has the language code in the url path like this which is correct:
http://mylocal/es/test-1f-spanish
But when click to go to the Content overview the url path still has the language code in the url path like this:
http://mylocal/es/admin/content
And any other page I click on still has the language code in the url:
http://mylocal/es/admin/content/media
This is not correct, is it a setting in Language detection. /admin/config/regional/language/detection
Comment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedLooked into this and tracked down the problem.
Updating the issue summary. I don't mind this staying in the content_moderation component since it's the only place where this actually surfaces (people might be more likely to find it here?), but I believe the fix and test should be in
node. Happy to change the component if anyone feels differently.Uploading the fix to see if anything else fails.
Comment #6
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAdding tests for this exposed another place where this problem existed. Attaching tests and a fix for that too.
Comment #7
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #9
StephaneQI also had this issue and applying patch #6 solved it (tested only on the "Moderated content" tab).
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI was expecting these relationships to be added by
\Drupal\views\EntityViewsData, but apparently that's not the case. I think we should open a followup to do that because it's needed by all content entity types. AndNodeViewsDataneeds quite some cleanup as well.In the meantime, I manually tested the patch and it works great, so it's a good step forward :)
Comment #11
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThanks for the review!
I think we might be doing that in #2652652: Provide a relationship from the revision table to the main table.
Comment #12
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedNice! Here's another quick cleanup for something that I found while looking at
NodeViewsData: #3002158: Clean up dead code in NodeViewsDataComment #13
jibranWe are changing the views data which will affect the query. For view data changes to be applied we need to clear the cache. We just need to add an empty post update hook.
Comment #14
jibranComment #15
greggmarshallI do not believe the patch in #6 solves the problem, at least for the use case I tested it with
Even setting the Moderated Content filter to English displays "No moderated content available. Only pending versions of content, such as drafts, are listed here."
I did notice that if I edit the English draft and save it without changing the state, now only the English draft shows in Moderated Content. It would appear that view is only displaying the most recent revision (and the one with status = 0, saving the English draft switched the Spanish to status = 1 and the English to status = 0 from the previous revision ID which had them the other way).
I would expect to see both the English AND the Spanish drafts in the Moderated Content page since both are in the draft state.
Comment #16
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThanks for the report. I've responded to the issue you logged in #3007456: Content Moderation State Field Revision with 2 Languages Set to Published.
Comment #17
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAdding the cache clear as per @jibran's request.
Comment #18
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedNice, back to RTBC then.
Comment #19
ergonlogicThe latest patch includes the addition of
views_update_8701()innode.install. This breaks the hook magic naming convention, and causes failures when runningdrush updb. The attached patch just renames the function tonode_update_8701(), but is otherwise identical.Comment #20
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThat's a very good catch, @ergonlogic!
Comment #21
pavlosdan CreditAttribution: pavlosdan as a volunteer commentedPatch solves the duplicated content issue for us as well. Thanks! :)
Comment #22
catchThis should be a post-update rather than hook_update_N(). Otherwise looks good though.
Comment #23
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAddressing #22. Not sure why post update is preferable here, but happy to defer.
Comment #24
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@Sam152, some reasons for that are listed here: https://www.drupal.org/node/2960601
Comment #25
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedGood to know! Thanks.
Comment #26
catchCommitted 75a159c and pushed to 8.7.x. Thanks!
Comment #28
tacituseu CreditAttribution: tacituseu commentedThis introduced test failures:
https://www.drupal.org/pift-ci-job/1125517
https://www.drupal.org/pift-ci-job/1125518
Comment #30
alexpottReverted. It looks like the fails are on other DBs
Comment #31
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAh, I think we can into a similar issue in the moderation_state sorting issue. We might need to add an additional sort criteria to the test views, to ensure the order in the test is always consistent.
Comment #32
jibranAh! the old sorting issue. MySQL let's get away with a lot.
Comment #33
luisnicg CreditAttribution: luisnicg as a volunteer commentedAfter applying the patch I was able to see the correct edited nodes in the moderated content view but I'm getting a new issue:
The state '' does not exist in workflow.
I have two languages Spanish and English, I edited the node in "en" (I also changed the state to Draft), after that I tried to edit the node in "es", I could not edit it given I got that error.
I didn't find the revision ID of the node in the 'content_moderation_state_field_data ' table, it didn't get this value $entity->moderation_state->value in the EntityTypeInfo.php file.
Here is where the error came up:
EntityTypeInfo.php file
Line 349
Is there someone who has the same issue?
Comment #34
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commented@luisnicg, I don't think that is related to the join in the node module. It would be good if you could file a new issue with detailed steps to reproduce the issue, including the version of core you are running.
Comment #35
BerdirSounds like #3000573: After enabling Workflows and Content Moderation there is a fatal error when trying to edit content translation, which has been fixed in 8.6.x-dev.
Comment #36
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedAdding some additional sorts which hopefully address the random fails in the other DB engines. Queuing tests on both branches and the other DB engines.
Comment #38
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThe one failed run wasn't related to this test:
Comment #39
alexpottCommitted ab43176 and pushed to 8.7.x. Thanks!
Committed bc60cf1 and pushed to 8.6.x. Thanks!
Backported to 8.6.x because this does not have a complicated update path and it is a bug.
Fixed coding standards on commit.
Comment #43
quicktrick CreditAttribution: quicktrick commentedDrupal 8.8.1
I encountered the same issue after I added the language translation to the users (admin/config/regional/content-language).
After I removed the users translation the issue persisted until I manually deleted the translation record for the translated user from the database table `users_field_data` and cleared the cache.
Anyway, I'd like to use users translation and not have the duplicates on the admin/content page.