Generated with the help of an LLM.

Problem/Motivation

BatchNegotiator::determineActiveTheme() loads the batch only when $request->request->has('id'). That is the POST body. Batch URLs carry the ID in the query string (/batch?id=N&op=start), so the lookup never runs.

Normally _batch_page() loads the batch into batch_get() before the theme is initialized, and the negotiator finds it there. If the theme is initialized while the batch is being unserialized, the negotiator finds nothing. A stored object can do this in __wakeup(). ViewExecutable does.

Steps to reproduce

Store a batch with theme set to test_theme and an object that calls ThemeManager::getActiveTheme() in __wakeup(). Set the default theme to stark. Call BatchStorage::load() for /batch?id=N&op=start. The active theme is stark. Expected: test_theme.

Proposed resolution

Read the ID from $request->query. Skip the lookup while the negotiator is already loading the batch. Otherwise unserializing the batch calls the negotiator again. Cover both with kernel tests.

Remaining tasks

  • Review the test-only change (fails without the fix).
  • Review the fix.
  • Backport to 11.x.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

Issue fork drupal-3636379

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

voleger created an issue. See original summary.

voleger’s picture

Assigned: Unassigned » voleger
Status: Active » Needs work

voleger’s picture

Title: BatchNegotiator reads the batch ID from the POST body, so the starting theme is not restored » BatchNegotiator reads the batch ID from the POST body, but batch URLs carry it in the query string
Issue summary: View changes
voleger’s picture

Assigned: voleger » Unassigned
Issue summary: View changes
Status: Needs work » Needs review

The first fix commit (4402a87c65c) broke UserBatchActionTest with a call stack overflow. BatchStorage::load() unserializes the batch. The batch in that test holds a ViewExecutable, and ViewExecutable::__wakeup() initializes the theme. That calls BatchNegotiator again, which loads the batch again.

The earlier code never hit this, because the lookup branch could not run.

Commit 55b71e4a2c3 adds a flag, so the negotiator skips the lookup while it is already loading the batch. It adds a kernel test with an object that initializes the theme in __wakeup(). The test fails without the flag.

A batch with such an object gets the batch theme. The nested negotiation returns NULL, and the outer negotiation sets the batch theme afterwards. With default theme stark and batch theme test_theme, the active theme after BatchStorage::load() is stark on unfixed code and test_theme on this branch. 91f3c883d93 changes the test to use these two themes.

voleger’s picture

Issue summary: View changes

Update IS

voleger’s picture

Issue summary: View changes