Problem/Motivation
WorkspaceManager::executeInWorkspace() and executeOutsideWorkspace() switch the active workspace, run a callback, then switch back. The switch back is skipped when the callback throws an exception, and, if the caller catches the exception, the rest of the request runs in the wrong workspace.
Steps to reproduce
- Switch to a workspace.
- Call
executeOutsideWorkspace()with a callback that throws, and catch the exception. getActiveWorkspace()now returnsNULL.
Proposed resolution
Wrap the callback in try/finally.
Issue fork drupal-3641672
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:
- 3641672-workspace-switch-exceptions
changes, plain diff MR !17959
Comments
Comment #3
amateescu commentedComment #4
smustgrave commentedRan the test job
Wasn't entirely sure how to trigger the error described naturally but the change makes sense to ensure
doSwitchWorkspaceis always called.Comment #9
catchCommitted/pushed to main and cherry-picked back through to 11.5.x, thanks!