"The website encountered an unexpected error" when database indexes are also present

Created on 26 March 2025, 11 days ago

Problem/Motivation

When Search API has configured indexes with the Database backend, a Fatal error is thrown.

Steps to reproduce

  1. Configure a site with both a database backend index and a Solr index.
  2. Enable the module then visit /solr-health-check
  3. A Fatal error is shown (The website encountered an unexpected error. Try again later.).
  4. In the PHP error log, the error is:
    Uncaught PHP Exception Error: "Call to undefined method Drupal\\search_api_db\\Plugin\\search_api\\backend\\Database::getSolrConnector()" at /var/www/modules/contrib/solr_health_check/src/Controller/HealthCheckController.php line 73

Proposed resolution

It's confusing this error is thrown at all, as the code in question is inside a try ... catch (\Exception $e) block.

Adding a method_exists() check at that line stops the error:

if (method_exists($backend,'getSolrConnector')) {

See attached patch which adds this change.

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

🇨🇦Canada damien_vancouver

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

Comments & Activities

Production build 0.71.5 2024