Problem/Motivation

The SearchApiCachePluginTrait doesn't account for when an index is disabled, but there's still an attempt to query it. This results in a 500 error.

Steps to reproduce

  1. Create a View that uses that index. Best create a page display.
  2. Create some content to be indexed by the server.
  3. Disable the server.
  4. Access the page display of the View. The requets should result in a 500 error.

Proposed resolution

In SearchApiCachePluginTrait::cacheSet(), add a check to see if $searchApiSearchQuery is set before using it.

CommentFileSizeAuthor
#2 3564177-1.patch1.54 KBalbionbrown
search_api.patch1.54 KBalbionbrown

Issue fork search_api-3564177

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

albionbrown created an issue. See original summary.

albionbrown’s picture

StatusFileSize
new1.54 KB

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

drunken monkey’s picture

Version: 8.x-1.40 » 8.x-1.x-dev
Component: General code » Views integration
Status: Active » Needs review
Issue tags: -Search API, -disable, -disabled, -views

Thanks for reporting this problem and already providing a patch!
We now use MR for working on changes, though – I created one with the changes from your patch and also added test coverage.

Just one more question, otherwise I think this is ready to be merged: Your patch also contains changes to SearchApiMoreLikeThis. Are these related and also necessary or did you just include them by mistake? In the former case, could you quickly explain why those are needed?

PS: It seems you (like many others – it's really easy to misinterpret) are confused by the "Issue tags" field. As the guidelines state, they aren't meant for free text tags related to the issue, but only for specific categorization purposes, usually by module maintainers.
So, if you aren't sure your current usage is correct, please just leave the field empty.

jvollebregt-swis’s picture

Found this issue when searching for my error. I'm getting a Call to a member function setOption() on null in SearchApiMoreLikeThis::query which was fixed by the patch. I presume it was deliberate.

Not sure if checking the index is the more robust solution instead of just checking if getSearchApiQuery() returns anything like the patch does in SearchApiCachePluginTrait but it works in my case.