Call to a member function getTypedData() on null

Created on 3 November 2024, about 1 month ago

Problem/Motivation

I get following error on my MLT views based search, which is really strange.

Error: Call to a member function getTypedData() on null in Drupal\elasticsearch_connector\SearchAPI\MoreLikeThisParamBuilder->buildMoreLikeThisQuery() (line 67 of modules/contrib/elasticsearch_connector/src/SearchAPI/MoreLikeThisParamBuilder.php).

My search_api index is based on nodes and aggregator items from drupal/aggreagtor contrib module (previously core module).

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

8.0

Component

Code

Created by

🇩🇪Germany IT-Cru Munich

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

Merge Requests

Comments & Activities

  • Issue created by @IT-Cru
  • 🇩🇪Germany IT-Cru Munich

    My little change in IF-statement on opened MR fixed this issue.

    Strange thing is, that in both variants entity gets loaded properly, but only with my change in IF-statement $entity-getTypedData() doesn't throw any error.

  • Pipeline finished with Success
    about 1 month ago
    Total: 240s
    #328144
  • 🇨🇦Canada mparker17 UTC-4

    @it-cru, awesome, thank you very much!

    This patch looks great!

    But, I think this is a common-enough scenario that we should have a test to make sure that this issue doesn't regress (that's why I'm marking it as "Needs work" and adding the "Needs tests" tag).

    @it-cru, do you feel comfortable writing a test? (I am happy to help if you'd like!) If not, then I would be happy to write the test.

    I think the reason why your change makes the error go away is because there are some cases where $this->entityTypeManager->getStorage($entity_type_id)->load($id) returns NULL (e.g.: I could see this happening if an entity was deleted from Drupal, but the corresponding entry in the ElasticSearch index hadn't been deleted yet).

    Because PHP interprets NULL as "false-y", the subsequent code (i.e.: $datasource->getItemId($entity->getTypedData())) isn't run (and doesn't throw an error) after your change.

Production build 0.71.5 2024