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;
        }
CommentFileSizeAuthor
search_api_null_hasWarning.patch508 bytesmr.baileys

Issue fork search_api-3529324

Command icon 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

mr.baileys created an issue. See original summary.

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Bitten by this one too and running the same patch locally.

drunken monkey made their first commit to this issue’s fork.

drunken monkey’s picture

Thanks 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.

drunken monkey’s picture

Would be great to get just a quick confirmation that the code in the MR (patch here) works.

swentel’s picture

Running that version of the patch now, no errors so far, so works for me!

  • drunken monkey committed 4eba932d on 8.x-1.x
    Issue #3529324 by mr.baileys, drunken monkey, swentel: Fixed fatal error...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Great to hear, thanks for reporting back!
Merged.

gauravjeet’s picture

the MR works, thanks for the fix!!

Status: Fixed » Closed (fixed)

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