Set Cache strategy with Grouping on a View results in error

Created on 5 November 2024, 6 months ago

Problem/Motivation

TypeError: array_merge(): Argument #1 must be of type array, null given in array_merge() (line 72 of modules/contrib/search_api_grouping_solr/src/Plugin/search_api/processor/DenormalizeAltering.php).

Stack trace:
Drupal\search_api_grouping_solr\Plugin\search_api\processor\DenormalizeAltering->preprocessSearchQuery(Object) (Line: 666)
Drupal\search_api\Entity\Index->preprocessSearchQuery(Object) (Line: 592)
Drupal\search_api\Query\Query->preExecute() (Line: 298)
Drupal\search_api\Plugin\views\cache\SearchApiTagCache->alterCacheMetadata(Object) (Line: 2365)
Drupal\views\Plugin\views\display\DisplayPluginBase->calculateCacheMetadata() (Line: 331)
Drupal\views\Entity\View->addCacheMetadata() (Line: 305)
Drupal\views\Entity\View->preSave(Object) (Line: 528)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 483)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 257)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 354)
Drupal\Core\Entity\EntityBase->save() (Line: 614)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 1007)
Drupal\views_ui\ViewUI->save() (Line: 357)
Drupal\views_ui\ViewEditForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 129)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('view_edit_form', Array, Object) (Line: 326)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'edit', Array) (Line: 220)
Drupal\views_ui\Controller\ViewsUIController->edit(Object, 'block_1')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 263)
Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 219)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

- Follow module's instructions to setup a Solr index with Search API using Denormalized processors (both Denormalization and Denormalization- Altering)
- Create a Drupal View for this solr Index - block display
- Use Responsive Grid Format and enable "Force using fields" in its Settings
- Add a field in this Drupal View
- Go back to the Format settings and use the "Grouping Field Nr. 1" to use that added field
- Verify the results are correct and are denormalized
- Head over to cache strategy in this Drupal View Advanced section
- Set the "Caching" to either Search API (tag-based) or Search API (time-based)
- Save the View
- Error ^^

Proposed resolution

Patch attached:

    if ($query->getOption('search_api_retrieved_field_values') != NULL) {
      $query->setOption('search_api_retrieved_field_values', array_merge(
        $query->getOption('search_api_retrieved_field_values'),
        array_keys($denormalization->getDenormalizationFields())
      ));
    }

Remaining tasks

The above proposed resolution does seem to resolve the error but somehow loses the denormalized structure of the document returned via solr. This does not work!

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇮🇳India gauravjeet

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

Comments & Activities

Production build 0.71.5 2024