Fatal error when views caching is enabled

Created on 6 March 2024, over 1 year ago

Getting a fatal error for a search api view but only when views cache is enabled.
This is a search-api based views page display.

here's the code snippet that's fataling:

        // Trick Search API into believing a search happened, to make faceting
        // et al. work.
        /** @var \Drupal\search_api\Query\ResultSetInterface $results */
        $results = $cache->data['search_api results'];
        $this->getQueryHelper()->addResults($results);

error:

TypeError: Drupal\search_api\Utility\QueryHelper::addResults(): Argument #1 ($results) must be of type Drupal\search_api\Query\ResultSetInterface, null given, called in web/modules/contrib/search_api/src/Plugin/views/cache/SearchApiCachePluginTrait.php on line 186 in Drupal\search_api\Utility\QueryHelper->addResults() (line 86 of modules/contrib/search_api/src/Utility/QueryHelper.php).

stack trace:

Drupal\search_api\Plugin\views\cache\SearchApiTagCache->cacheGet('results') (Line: 1434)
Drupal\views\ViewExecutable->execute() (Line: 195)
Drupal\facets\Plugin\facets\facet_source\SearchApiDisplay->fillFacetsWithResults(Array) (Line: 464)
Drupal\facets\FacetManager\DefaultFacetManager->updateResults('search_api:views_page__site_search__site_search_page') (Line: 250)
Drupal\facets\FacetManager\DefaultFacetManager->processFacets('search_api:views_page__site_search__site_search_page') (Line: 327)
Drupal\facets\FacetManager\DefaultFacetManager->processBuild(Object) (Line: 387)
Drupal\facets\FacetManager\DefaultFacetManager->build(Object) (Line: 91)
Drupal\facets\Plugin\Block\FacetBlock->build() (Line: 171)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func_array('Drupal\block\BlockViewBuilder::preRender', Array) (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback('Drupal\block\BlockViewBuilder::preRender', Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 858)
Drupal\Core\Render\Renderer->doCallback('#pre_render', 'Drupal\block\BlockViewBuilder::preRender', Array) (Line: 421)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 493)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 146)
__TwigTemplate_18773072bf7da0d86d76cb5c2b506a70->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array) (Line: 38)
Twig\TemplateWrapper->render(Array) (Line: 39)
twig_render_template('profiles/contrib/example/themes/example/templates/system/page.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 480)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 90)
__TwigTemplate_69754bf01e0e582127c33886d4a284c2->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array) (Line: 38)
Twig\TemplateWrapper->render(Array) (Line: 39)
twig_render_template('profiles/contrib/example/themes/example/templates/system/html.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 480)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 159)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
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: 50)
Drupal\ban\BanMiddleware->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: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
๐Ÿ› Bug report
Status

Active

Version

1.31

Component

General code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States AaronBauman Philadelphia

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

Comments & Activities

  • Issue created by @AaronBauman
  • Status changed to Postponed: needs info over 1 year ago
  • ๐Ÿ‡ฆ๐Ÿ‡นAustria drunken monkey Vienna, Austria

    Thanks a lot for reporting this problem!

    However, Iโ€™m afraid I canโ€™t reproduce this, and as lots of people are using this module it seems unlikely that this is a wide-spread problem. It is probably still a bug in this or a related module, but most likely one restricted to specific setups, which makes it harder to debug.
    It would therefore be great if you could provide additional information:

    • First off, have you tried with the latest dev version of this module? The bug may already be fixed there.
    • Did this start to happen with a recent update of this or a related module, or is this a new installation where this has been happening from the start? In the former case, it would be great if you could pinpoint the exact version/commit where this bug was introduced.
    • The stacktrace of the error shows that this particular view execution was triggered by a facet, not the normal search. Does this also happen for normal searches, or only when displaying facets on other pages? Does the error also occur when disabling the Facets module?
    • Are there any warnings/errors in your logs when this happens that might be related?

    It would be very easy to fix this particular error, but as I canโ€™t really explain why this would even happen I think itโ€™s important to track down the root cause of this issue. Otherwise we might just be masking some larger problem.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States AaronBauman Philadelphia

    Thanks for the feedback, i'll followup here if i get a chance to dig into it.

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil yseki

    I have the same issue, and as I got from the code, search_api is trying to "hacking" the view result with the cached values. Happens that not always we have the cached values for that, and the code uses a NULL value inside a function that is expecting a ResultSetInterface value.

    As a quick fix, I added just a condition to verify if the cached value matches the expected parameter type before calling the helper function.

    Patch is attached.

Production build 0.71.5 2024