When trying to run cron (http://***/admin/config/system/cron) I receive WSOD with an error related to search_api_facets.module.

Fatal error: Call to a member function entityWrapper() on a non-object

Debug info

Array
(
    [type] => 1
    [message] => Call to a member function entityWrapper() on a non-object
    [file] => /***/sites/all/modules/search_api/contrib/search_api_facets/search_api_facets.module
    [line] => 922
)

Environment

  • Drupal 7.7
  • Support from Acquia helps fund testing for Drupal Acquia logo

    Comments

    drunken monkey’s picture

    Version: 7.x-1.x-dev » 7.x-1.0-beta10
    Status: Needs review » Active
    FileSize
    1.3 KB

    I'm pretty sure where the problem lies: you seem (for whatever reason) to still have facets for an already deleted index, resulting in this error.

    For catching this and avoiding the fatal error, please test the attached patch.

    Then, for cleaning up your data, execute the following SQL statement:
    DELETE FROM search_api_facet WHERE index_id NOT IN (SELECT machine_name FROM search_api_index)
    (Of course, add the appropriate table prefixes if you have one defined.)

    drunken monkey’s picture

    Version: 7.x-1.0-beta10 » 7.x-1.x-dev
    Status: Active » Needs review
    Issue tags: -WSOD
    Refineo’s picture

    Version: 7.x-1.0-beta10 » 7.x-1.x-dev
    Status: Active » Needs review
    DELETE FROM search_api_facet WHERE index_id NOT IN (SELECT machine_name FROM search_api_index)
    executed (8 records deleted)
    
    Refineo’s picture

    The cron run successfully after deleting obsolete records (above).

    Now testing the patch for error handling (after creating some test data)...

    Refineo’s picture

    Status: Needs review » Reviewed & tested by the community

    Applying the patch makes no harm to the module but I cannot get the error handling message even after removing indices and leaving facet data so I cannot fully confirm the new code handles errors.

    drunken monkey’s picture

    Title: Fatal error: Call to a member function entityWrapper() on a non-object » Fix error handling for orphaned facets
    Status: Reviewed & tested by the community » Fixed

    Yes, that's why I suggested to do it in the other order. Anyways, I'm pretty sure this fixes at least that instance of the bug.
    Also, since we will very soon abandon the Facets module anyways (see #1182614: Integrate with Facet API), more complicated bug fixing would be wasted anyways.

    Committed this, thanks for reporting and testing!

    miiimooo’s picture

    Status: Fixed » Active

    Sorry re-opening. I just upgrade a site from my dev version to the current recommended one 1.0-beta9 and now I'm stuck with this error..

    Call to a member function entityWrapper() on a non-object in
    /search_api/contrib/search_api_facets/search_api_facets.module on line 922

    EDIT: all my facets refer to the same existing index

    drunken monkey’s picture

    Status: Active » Fixed

    1) Beta 10 is the recommended version.
    2) If it's not in the dev version, I can't do anything about it. The dev version already catches this error.

    Weird, though, that this should occur with valid facets. However, I could imagine that search_api_index_load() in general doesn't work for you at the moment, if the entity type information is outdated. To fix, execute cache_clear_all('entity_info:', 'cache', TRUE); (or manually delete those entries from the cache table).

    miiimooo’s picture

    Just to confirm the 'fixed': I got this error I think mainly because I hadn't upgraded entity API. Upgrading everything (search_api, search_api_solr, entity) in one go to beta10 worked!

    Status: Fixed » Closed (fixed)

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