Problem/Motivation

On Drupal 11, because of some cache unserialization done by search_api, ViewsBulkOperationsBulkForm is instantiated twice, and so the ViewsBulkOperationsViewData service is initialized twice too. First with the valid original view, and then with the view unserialized from cache.

Sadly, the unserialized view is always empty for some reason, so it totally breaks VBO as it uses both objects simultaneously in the viewsForm method below:

    // Only add the bulk form options and buttons if
    // there are results and any actions are available.
    $action_options = $this->getBulkOptions();
    if (!empty($this->view->result) && !empty($action_options)) {

      // Get bulk form keys and entity labels for all rows.
      $entity_data = $this->viewData->getViewEntityData();

First we use $this->view->result from the original valid view object and then $this->viewData->getViewEntityData() which uses the result from the unserialized view which is always empty.

So we get in an inconsistent state that breaks VBO.

Steps to reproduce

Use VBO with search_api on Drupal 11.

Here is the code in Search API that gets the View from cache:

https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/src/Plugin/views/cache/SearchApiCachePluginTrait.php?ref_type=heads#L173

Here is the code in Views that calls initHandlers during unserialization:

https://git.drupalcode.org/project/drupal/-/blob/11.0.5/core/modules/views/src/ViewExecutable.php?ref_type=tags#L2585

Proposed resolution

Quick and dirty hack : clone the ViewsBulkOperationsViewData object so the original one is not overridden during the second init call.

Remaining tasks

Find a more suitable and/or permanent solution to the problem.

CommentFileSizeAuthor
#5 views_bulk_operations-3485284-MR93-5.patch802 bytesmably
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

mably created an issue. See original summary.

mably’s picture

Issue summary: View changes
mably’s picture

Issue summary: View changes

mably’s picture

StatusFileSize
new802 bytes
mably’s picture

Issue summary: View changes
mably’s picture

Issue summary: View changes
mably’s picture

Status: Active » Closed (works as designed)

Ok, it looks like the View shouldn't have been serialized but only some data like the View results.

In fact the search_api module adds some dependency to the ViewExecutable in the following code:

https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/src/Plugin/views/query/SearchApiQuery.php?ref_type=heads#L285

$this->query->setOption('search_api_view', $view);

The query gets serialized and though, the full ViewExecutable comes with it.

So it may be a bug on search_api side.

But could we try to handle it properly on VBO side?

mably’s picture

Status: Closed (works as designed) » Active
scottm316’s picture

This definitely fixes the problem for me. Thanks a lot!