Warning: Invalid argument supplied for foreach() in Drupal\acquia_search\PreferredSearchCoreService->getPreferredCore()

Created on 12 April 2022, over 2 years ago
Updated 15 March 2024, 9 months ago

Problem/Motivation

I'm getting this warning every time I access any page, it begun on version 7.x-3.9 but still happens on 7.x-3.10.
I don't know if this is some missing configuration on my side, but I couldn't find the problem, and Solr Searching is working fine, we had this setup for years and never had a problem with it, but this warning is annoying and causing some issues with deploy pipelines and some other stuff, so we had to downgrade the module to 7.x-3.8 to fix the issue. Here's the warning:
Warning: Invalid argument supplied for foreach() in Drupal\acquia_search\PreferredSearchCoreService->getPreferredCore() (line 85 of /docroot/sites/all/modules/contrib/acquia_connector/acquia_search/src/PreferredSearchCoreService.php).

Steps to reproduce

Proposed resolution

I've compared the two versions (7.x-3.9 and 7.x-3.8), from my analysis I found out that the code part that is causing this issue is at acquia_search/acquia_search.module from line 109 to 119, specifically the line 110 which is calling isPreferredCoreAvailable() method, which calls getPreferredCore() method, which is trying to run a foreach loop on variable $this->available_cores, but it's not checking if this variable is iterable beforehand, and I think that we can do a quick and easy solution, just by checking if this variable it is iterable beforehand, this will prevent the warning, and since everything is working with this it's just the annoying warning that we want to get rid, this should work just fine.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024