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

  1. Switch to a workspace.
  2. Call executeOutsideWorkspace() with a callback that throws, and catch the exception.
  3. getActiveWorkspace() now returns NULL.

Proposed resolution

Wrap the callback in try/finally.

Issue fork drupal-3641672

Command icon 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

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Ran the test job

Failed asserting that null is identical to 'stage'.
/var/www/html/core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php:907

Wasn't entirely sure how to trigger the error described naturally but the change makes sense to ensure doSwitchWorkspace is always called.

  • catch committed 37f2a0fd on 11.5.x
    fix: #3641672 WorkspaceManager::executeInWorkspace() and...

  • catch committed e129e64e on 11.x
    fix: #3641672 WorkspaceManager::executeInWorkspace() and...

  • catch committed 367468ca on 12.0.x
    fix: #3641672 WorkspaceManager::executeInWorkspace() and...

  • catch committed c706424d on main
    fix: #3641672 WorkspaceManager::executeInWorkspace() and...
catch’s picture

Version: main » 11.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main and cherry-picked back through to 11.5.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.