Problem/Motivation

The search index can contain items that are not available in Drupal's database or otherwise cannot be loaded as entities. This may happen when the site is run from an old database backup but on the newest search index.

When a search is executed and a deleted (not available) entity matches, the following error occurs on the result page:

Drupal\search_api\SearchApiException: Failed to load original object entity:node/5620:en in Drupal\search_api\Item\Item->getOriginalObject() (line 185 of modules/contrib/search_api/src/Item/Item.php).

Proposed resolution

The SearchApiPageController loads the original object and checks whether it casts to FALSE, continuing the loop if so. However, getOriginalObject() will throw a SearchApiException when it couldn't load the entity.

The call to getOriginalObject() needs to be in a try catch block that continues the loop whenever the exception occurs.

CommentFileSizeAuthor
#2 2872984-2.patch1.04 KBdietr_ch

Comments

dietr_ch created an issue. See original summary.

dietr_ch’s picture

Status: Active » Needs review
StatusFileSize
new1.04 KB
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

This looks solid.

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Committed.
Thanks, everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.