Problem/Motivation
When deleting a moderation state there can still be revision that have been saved in that moderation state. If there are revision saved in that moderation state, and the moderation state is deleted, you will get an error when vising the revision log for that entity like this:
InvalidArgumentException: The state 'need_review' does not exist in workflow. in Drupal\workflows\Plugin\WorkflowTypeBase->getState() (line 155 of /code/web/core/modules/workflows/src/Plugin/WorkflowTypeBase.php).
Steps to reproduce
- Install standard
- Install Content Moderation
- Add Content type
- Add content type to Editorial workflow
- Create Node with 2 revisions, one in Draft and one in Archived
- Delete the archived state
- Visit the node revisions page (i.e node/1/revisions)
Expanded stacktrace:
InvalidArgumentException: The state 'archived' does not exist in workflow. in Drupal\workflows\Plugin\WorkflowTypeBase->getState() (line 141 of core/modules/workflows/src/Plugin/WorkflowTypeBase.php).
Drupal\content_moderation\Plugin\WorkflowType\ContentModeration->getState() (Line: 45)
Drupal\content_moderation\StateTransitionValidation->getValidTransitions() (Line: 224)
Drupal\content_moderation\Hook\ContentModerationHooks->entityAccess()
call_user_func_array() (Line: 336)
Drupal\Core\Extension\ModuleHandler->{closure:Drupal\Core\Extension\ModuleHandler::invokeAll():335}() (Line: 287)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 335)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 100)
Drupal\Core\Entity\EntityAccessControlHandler->access() (Line: 103)
Drupal\node\NodeAccessControlHandler->access() (Line: 755)
Drupal\Core\Entity\ContentEntityBase->access() (Line: 188)
Drupal\node\Entity\Node->access() (Line: 72)
Drupal\Core\Entity\EntityAccessCheck->access()
call_user_func_array() (Line: 160)
Drupal\Core\Access\AccessManager->performCheck() (Line: 136)
Drupal\Core\Access\AccessManager->check() (Line: 93)
Drupal\Core\Access\AccessManager->checkNamedRoute() (Line: 282)
Drupal\Core\Menu\LocalTaskManager->getTasksBuild() (Line: 324)
Drupal\Core\Menu\LocalTaskManager->getLocalTasks() (Line: 92)
Drupal\Core\Menu\Plugin\Block\LocalTasksBlock->build() (Line: 221)
Proposed resolution
Check the workflow has a state before getting it in getValidTransitions
Remaining tasks
Review
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | workflow_error.png | 201.35 KB | mcroyle |
| #6 | Screenshot 2022-05-17 at 5.56.10 PM.png | 63.69 KB | rajandro |
Issue fork drupal-3265635
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
Comment #2
sam152 commentedComment #3
cilefen commentedDoes the Drupal UI allow deleting states that have revisions or did you delete the state with code?
Comment #4
matsbla commentedYes, the UI allowed to delete the states that have those revisions!
Comment #5
cilefen commentedThen this can be major priority.
Comment #6
rajandro commentedI have checked the issue in both 9.3.x and 9.4.x. For both scenarios, the functionality is working as expected and the following code is doing this checking perfectly!
@matsbla, If you still get this issue, could you please mention the steps to reproduce it? So I can reverify this again.
Thanks!
Comment #7
cilefen commentedComment #9
el1_1el commentedThe issue occurs when displaying revisions. If the node with any revision of a content moderation state that has been deleted is shown, the error occurs.
So add node x with workflow y that has states a, b and c. Show the revisions somewhere. Run node x through all 3 states. Then delete step b. Go to the display for node x revisions. You will get the error.
Unfortunately, I have 99 states over 6 workflows with 129 possible transitions (dont ask). I will have to fix the issue by updating content_moderation_state_field_revision with state a or c (or zzz given the volume) in the above scenario(Updated) A better solution seems to be just deleting the transitions and keeping the legacy states... if you havent deleted them already in production that is.
Comment #10
mcroyle commentedI'm also experiencing this. When I attempt to visit Content -> Moderated Content, I receive an error that an old workflow state does not exist in workflow.
None of my nodes are are in this workflow state, however, some had been assigned this state in prior revisions.Edit: There was a piece of content still in the old workflow state. I was able to re-add the state and the moderation page displayed correctly. I'm not sure how the state was able to be removed originally.
Comment #12
smustgrave commentedBased on #9 and #10 seems like it could still be a problem
Comment #13
wweibel commentedIssue is still present in 10.1.2
An approach would be to default to the 'Default State' of the workflow in these instances. Or when deleting a state require the new state be selected and update all the revisions.
I would prefer the later to avoid stale data being present. Removing the ability to delete states (if there are revisions in that state) is rather heavy handed and virtually guarantees that no state could ever be deleted, and would not reflect changes to human workflow.
Workaround, that can be placed in a post-update-hook:
Comment #14
sahana _n commentedHi
I tried to reproduce the issue in Drupal 11. x but the issue is not reproducible in Drupal 11. x.
I attached the screen recording, please review it.
Please let me know if I made any mistakes.
Thanks!!
Comment #15
phjouI confirm I have the same issue, I can delete the workflow state, and then the nodes that were using it have a broken revisions list page.
I approve that the interface should allow to pick a new workflow state to replace the one that has been deleted.
Comment #17
acbramley commentedThis was just reported in Diff #3617616: Revision overview fatals when a revision's moderation state no longer exists in the workflow but fixing it there still requires a fix in core. Reproduced easily on main branch.
Comment #18
acbramley commentedClarifying steps because #14 visits the revision page itself, not the revisions overview.
Comment #19
acbramley commentedComment #21
acbramley commentedAI disclosure - Claude helped write the tests in https://git.drupalcode.org/project/drupal/-/merge_requests/16751/diffs, I have reviewed and manually edited all code afterwards.
MR includes the fix and test coverage for the low level service as well as an integration test ensuring the revisions page doesn't break.
Comment #22
acbramley commentedComment #23
smustgrave commentedper the comment @acbramley made in the MR.