Problem/Motivation
One of my Drupal sites which uses search_api is spamming its logs with a lot of PHP warnings whenever a views page with search results is generated. The warnings are suppressed on prod, so they don't display, but the site is busy enough to generate several GB of these logs each day, which is not ideal :-)
The site runs on PHP 8.4.
prod|https://site|1794866998|php|192.178.6.105|https://site/url?query||0||Warning: Undefined property: Drupal\views\ResultRow::$_object in Drupal\search_api\Plugin\views\query\SearchApiQuery->getAllEntities() (line 806 of /srv/www/html/modules/contrib/search_api/src/Plugin/views/query/SearchApiQuery.php) #0 /srv/www/html/core/includes/bootstrap.inc(166): _drupal_error_handler_real()
#1 /srv/www/html/modules/contrib/search_api/src/Plugin/views/query/SearchApiQuery.php(806): _drupal_error_handler()
#2 /srv/www/html/modules/contrib/search_api/src/Plugin/views/query/SearchApiQuery.php(829): Drupal\search_api\Plugin\views\query\SearchApiQuery->getAllEntities()
#3 /srv/www/html/core/modules/views/src/Plugin/views/cache/CachePluginBase.php(252): Drupal\search_api\Plugin\views\query\SearchApiQuery->getCacheTags()
#4 /srv/www/html/core/modules/views/src/ViewExecutable.php(1626): Drupal\views\Plugin\views\cache\CachePluginBase->getCacheTags()
#5 /srv/www/html/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2215): Drupal\views\ViewExecutable->getCacheTags()
#6 /srv/www/html/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2190): Drupal\views\Plugin\views\display\DisplayPluginBase->applyDisplayCacheabilityMetadata()
#7 /srv/www/html/core/modules/views/src/ViewExecutable.php(1593): Drupal\views\Plugin\views\display\DisplayPluginBase->render()
#8 /srv/www/html/core/modules/views/src/Plugin/views/display/Block.php(133): Drupal\views\ViewExecutable->render()
#9 /srv/www/html/core/modules/views/src/ViewExecutable.php(1690): Drupal\views\Plugin\views\display\Block->execute()
#10 /srv/www/html/core/modules/views/src/Element/View.php(81): Drupal\views\ViewExecutable->executeDisplay()
#11 /srv/www/html/core/modules/views/src/Plugin/Block/ViewsBlock.php(61): Drupal\views\Element\View::preRenderViewElement()
#12 /srv/www/html/modules/contrib/panels/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php(138): Drupal\views\Plugin\Block\ViewsBlock->build()
#13 /srv/www/html/modules/contrib/panels/src/Plugin/DisplayBuilder/StandardDisplayBuilder.php(200): Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder->buildRegions()
#14 /srv/www/html/modules/contrib/panels/src/Plugin/DisplayVariant/PanelsDisplayVariant.php(346): Drupal\panels\Plugin\DisplayBuilder\StandardDisplayBuilder->build()
#15 /srv/www/html/modules/contrib/page_manager/src/Entity/PageVariantViewBuilder.php(29): Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant->build()
#16 /srv/www/html/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php(134): Drupal\page_manager\Entity\PageVariantViewBuilder->view()
#17 [internal function]: Drupal\Core\Entity\Controller\EntityViewController->view()
#18 /srv/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#19 /srv/www/html/core/lib/Drupal/Core/Render/Renderer.php(637): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext():121}()
#20 /srv/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#21 /srv/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#22 /srv/www/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::onController():96}()
#23 /srv/www/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#24 /srv/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#25 /srv/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#26 /srv/www/html/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#27 /srv/www/html/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#28 /srv/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(201): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#29 /srv/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(138): Drupal\page_cache\StackMiddleware\PageCache->fetch()
#30 /srv/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(87): Drupal\page_cache\StackMiddleware\PageCache->lookup()
#31 /srv/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#32 /srv/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#33 /srv/www/html/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#34 /srv/www/html/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#35 /srv/www/html/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#36 /srv/www/html/index.php(19): Drupal\Core\DrupalKernel->handle()
#37 {main}.
Steps to reproduce
Honestly, I'm not sure. I inherited this site. Search_api is pointed at a solr index.
Proposed resolution
A recent change in commit d6ef078a9b2ca8a895d50893bfe580411db7059f modified the code, but still doesn't take into account the property it's using may not be set (which I suppose depends on the search backend/plugin being used)
Check if `->$_object` is set via empty() before trying to use it. The previous version of the code had an inline `?? NULL` but that caused the same warnings in the logs.
Remaining tasks
Issue fork search_api-3638701
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
Comment #3
cafuego commented