Closed (fixed)
Project:
Search API
Version:
8.x-1.x-dev
Component:
Views integration
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Nov 2022 at 11:57 UTC
Updated:
21 Apr 2025 at 07:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
andrew-minich commentedAttaching the patch that adds null-safe preExecute call for an empty query.
Comment #3
shriaasSeems like this error occurs at multiple places hence created a META issue for it.
Comment #4
shriaasGetting the same error on line 293, added null safe operator.
Comment #5
shriaasComment #6
anaconda777 commentedHi,
Applied the patch #4 to 1.28.0 but still got this message:
PHP message: Error: Call to a member function getResults() on null in /var/www/html/learn_test/web/modules/contrib/search_api/src/Plugin/views/query/SearchApiQuery.php on line 867 #0Comment #7
siddharthjain commentedAdded the patch for the issue mentioned in #6, here is the updated patch(Call_on_Null-3321499-7.patch) and interdiff_4-7.txt
Comment #8
mialdi98 commentedSituations, when indexes are disabled, won't lead you to a fatal error using views with search_api, thanks to this patch.
#7 works for me.
Comment #9
drunken monkeyThanks a lot for your comment, mialdi98, this is the first clue to the cause of this issue. With this, I was also easily able to reproduce at least one of the errors.
Can others confirm that they also have a disabled search index on their site?
Otherwise, it would be very important to know why
getSearchApiQuery()returnsNULL, so that we don’t just apply a band aid that fixes the symptoms but ignore the underlying problem.Regarding the patches: We don’t yet depend on PHP 8, so please use the long syntax for null safety. Patch attached, please test/review!
Comment #10
heddnIn my case, I did have a disabled search index when running
facets_update_8010. The patch in #9 fixed the issue.Comment #11
supreetam09 commentedWe had the same issue and under same scenarios.
We had a disabled search index and we ended up on the same error. Also other update hooks from Facet module
facets_update_8012was failing for the same error.I can also confirm after applying the patch #9, the issue got fixed. Thanks for the patch.
I think we can move to RTBC!
Comment #13
drunken monkeyGood to hear, thanks for testing and reporting back!
Merged.
Thanks again, everyone!
Comment #14
supreetam09 commentedI think the previous patch/commit is still incomplete as I landed on the error while accessing view:
TypeError: Drupal\search_api\Utility\QueryHelper::addResults(): Argument #1 ($results) must be of type Drupal\search_api\Query\ResultSetInterface, null given, called in /var/www/html/docroot/modules/contrib/search_api/src/Plugin/views/cache/SearchApiCachePluginTrait.php on line 186 in Drupal\search_api\Utility\QueryHelper->addResults() (line 86 of modules/contrib/search_api/src/Utility/QueryHelper.php).Its kind of expected since the query is NULL, so the result set in https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/src/Plugin/... also becoming null.
Since previous patch is already committed, adding a second patch to fix it (excluding the changes in #9). Please review!
For people who are facing such, you need both this patch and the patch in #9 to make it work.
Comment #15
drunken monkeyThanks for reporting this, that indeed seems to be a similar probolem.
However, the solution is probably to avoid caching a
NULLresult in the first place, not to add a check when retrieving it.Patch attached, please test/review!
Comment #19
lokeshwari commentedComment #20
namisha jadhav commentedRe-written patch #15 to be compatible with the latest version.
Comment #21
drunken monkey@namisha jadhav: Thanks! I added that to the MR, let’s see what the test bot says.
Comment #22
hmdnawaz commentedI use Drupal 11.0.12, search API 8.x-1.38, and search API Solr 4.3.8. In view, I'm using the cache as a Search API tag-based.
TypeError: Drupal\search_api\Utility\QueryHelper::addResults(): Argument #1 ($results) must be of type Drupal\search_api\Query\ResultSetInterface, null given, called in /var/web/vd16430/app/releases/303/web/modules/contrib/search_api/src/Plugin/views/cache/SearchApiCachePluginTrait.php on line 201 in Drupal\search_api\Utility\QueryHelper->addResults() (line 86 of /var/web/vd16430/app/releases/303/web/modules/contrib/search_api/src/Utility/QueryHelper.php).I used the patch from
MR 101, then cleared the cache, re-indexed all the items but I still see that error.While on Drupal 10.4, search API 1.35 and search API solr 4.3.4 and everything works fine with the views cache set to Search API tag-based.
Comment #23
drunken monkeyHuh, that’s very strange, no idea how this could even happen. Do you have any custom or third party caching code for Views results that might interfere? Do you also see a warning for an “undefined array key” before the
TypeErroroccurs?Would be very interesting to catch the moment where the faulty data is cached via a conditional breakpoint in
\Drupal\Core\Cache\DatabaseBackend::set()(or other used cache backend).But I guess for the sake of getting this long-running issue finally fixed we can also just add an explicit check for whether that key is empty and avoid using the cached data otherwise. Added to the MR, please test/review!
Comment #24
hmdnawaz commentedI don't see any warning before that TypeError occur. I do see array offset warnings after that
if ($cache = $this->getCacheBackend()->get($this->generateResultsKey())) {But that is because of the results are null.
I also noticed this warning which has search api in backtrace.
I don't know whether it is related or not.
But the latest commit indeed fixes the error.
Comment #25
drunken monkeyOh, yes, that is almost definitely related. It seems that the cached results data couldn’t be deserialized for some reason (maybe it got corrupted, potentially due to special characters?) and the Redis cache backend doesn’t correctly detect that case and still returns a cache hit. Then we get a cache hit back, but without any data, leading to this problem.
You should definitely look for an issue in the Redis module’s issue queue, or create it if there isn’t one already. However, also can’t hurt to guard against this eventuality in our own code. So, glad to hear this helped.
Can someone else confirm that the latest code in the MR works for them? Then I could finally merge this.
Comment #26
supreetam09 commentedWe have been using the patch from MR 101 and unable to reproduce the issue since. Hence setting to RTBC.
Comment #27
drunken monkeyGreat to hear, thanks for confirming!
Merged.
Thanks again, everyone!