Workflow doesn't recognize state change first time

Created on 21 February 2025, 1 day ago

Problem/Motivation

I'm filing this bug in case others are seeing similar behaviour, but I don't have a clear picture of what's involved yet. I'm working on a project with fairly complex use of Workflow module (including Workflow Access), as well as ECA and a variety of patches and newly-hatched contrib modules that are undoubtedly factors in the bug I'm seeing. I'll use this ticket to document my systematic testing to find a minimally reproducible version. Apologies if this is misplaced, but I'll take ownership to track this at least as far as identifying an actual bug (if any!)

Steps to reproduce

These steps reproduce the problem in my project environment reliably, but I haven't yet validated they work in a vanilla Workflow site:

  1. Create a workflow and add at least 3 states and transitions to it. Call them State1, State2, and State3, and let State1 be the default initial state upon creation. Configure transitions to have nodes progress through the states in order.
  2. Configure a node type with a workflow field and apply the workflow you created.
  3. Configure Workflow Access such that Role1 can create and push nodes to State1 and State2, and Role2 can push nodes from State2 to State3.
  4. Login with a Role1 user and create a node, immediately moving it to State2 (not sure if this is relevant, but it's what our test does)
  5. Login with a Role2 user and edit the node, attempt to move it to State2.
  6. Save the node with State2 selected, and observe the node update (seemingly) correctly (edits to other fields hold), but the State Transition hasn't happened (the Workflow tab on the node doesn't show any transition, and now entry is written to the database workflow_transition_history table).
  7. Edit the node again, and observe that the Workflow field widget is still in State1.
  8. Move the Workflow to State2 again.
  9. Save the node and observe that the State is correctly updated and a workflow transition entity is created.

Again, I'm not clear which of the specifics of these steps are relevant as yet, and I'm confident that some constellation of extra pieces we have in play is creating this behaviour, but this is the most reliable set of steps I have currently.

Proposed resolution

I spent a fair bit of time yesterday in my debugger, tracing the form submission at the point when the Role2 user tries to edit the node for the first time (aside: dang! this got a *lot* harder to do in D8+). I was able to validate that the form data is submitted correctly, and seems to arrive at the NodeForm::save() in the $form_state variable as I'd expect.

However, it appears as though the form handlers "lose" the new version of the to_sid value somewhere along the way, and I gather just end up assuming no transition is required. That said, without knowing the Workflow code paths very intimately, I'm reluctant to keep spinning my wheels taking this approach. I figure it's time to try and strip down the problem to its barest essentials.

Our project includes several other modules that are certainly relevant, and many more that might tangentially be involved here. Having exhausted the obvious ways to troubleshoot in-situ, I plan to build up a failing scenario from scratch, slowly re-introducing some of the miscellaneous modules that are in play (roughly in order of how likely I think the are to be at issue):

Remaining tasks

  1. Try to reproduce the equivalent behaviour in a vanilla Drupal site with only Workflow and Workflow Access modules.
  2. Introduce Workflow Required by State, and test again
  3. Introduce Workflow Save as Draft, and test again
  4. If both together cause the problem, test Workflow Save as Draft in isolation
  5. Reassess
  6. ...
  7. Profit?!
🐛 Bug report
Status

Active

Version

1.8

Component

Code

Created by

🇨🇦Canada spiderman Halifax, NS

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

Comments & Activities

Production build 0.71.5 2024