Problem/Motivation
When indexing, I'm running into a fatal error:
[error] Error: Call to a member function hasWarnings() on null in Drupal\search_api\Entity\Index->indexSpecificItems() (line 1057 of /var/www/html/docroot/modules/contrib/search_api/src/Entity/Index.php) #0 /var/www/html/docroot/modules/contrib/search_api/src/Entity/Index.php(974): Drupal\search_api\Entity\Index->indexSpecificItems(Array)
Looking at the code
$item = $items[$item_id] ?? NULL;
if ($item->hasWarnings()) {
$items_with_warnings[$item_id] = $item_id;
}
$item can be null, since ?? is used, so the next statement should take this into account. Something like:
$item = $items[$item_id] ?? NULL;
if ($item && $item->hasWarnings()) {
$items_with_warnings[$item_id] = $item_id;
}
Comments
Comment #2
swentel commentedBitten by this one too and running the same patch locally.
Comment #5
drunken monkeyThanks for reporting this problem and providing a patch.
Creating an MR so the test bot can take a look.
From the code, I’m not sure how this would ever happen, though? I guess the backend’s
indexItems()method returns item IDs as indexed that were not even passed to it in$items? That seems like a potential bug, or at least very hacky solution, in and of itself – but still, we should of course handle that reasonably.I changed the syntax slightly to use the
?->operator, would be great if someone could quickly confirm that this still solves the problem for them.Comment #6
drunken monkeyWould be great to get just a quick confirmation that the code in the MR (patch here) works.
Comment #7
swentel commentedRunning that version of the patch now, no errors so far, so works for me!
Comment #9
drunken monkeyGreat to hear, thanks for reporting back!
Merged.
Comment #10
gauravjeet commentedthe MR works, thanks for the fix!!