Problem with custom group fields when cache get returns NULL from 'CRM_Core_DAO_CustomGroup_QueryMultipleFields *' cache key
Overview
We had a problem where we did an APIv3 call on participants where it would cause an error resulting in a 500 response.
Some stack tracing showed us that in CRM/Core/BAO/CustomGroup.php the code $multipleFieldGroups = $cache->get($multipleFieldGroupCacheKey);
returned NULL (line 576). Since there is no check that says that it should not be NULL the code continues and errors on if (in_array($table, $multipleFieldGroups) &&
because
Argument #2 (closed) ($haystack) must be of type array, null given in in_array().
Reproduction steps
Could not specifically reproduce this with a clean install.
Current behaviour
Our page where the APIv3 Participant call was made would return a 500.
TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in in_array() (line 611 of /var/www/html/vendor/civicrm/civicrm-core/CRM/Core/BAO/CustomGroup.php)
#0 /var/www/html/vendor/civicrm/civicrm-core/CRM/Core/BAO/CustomGroup.php(611): in_array('civicrm_value_r...', NULL)
#1 /var/www/html/vendor/civicrm/civicrm-core/api/v3/utils.php(1449): CRM_Core_BAO_CustomGroup::getTree('Participant', Array, 1982, NULL, Array, NULL, true, NULL, true, false)
#2 /var/www/html/vendor/civicrm/civicrm-core/api/v3/Participant.php(154): _civicrm_api3_custom_data_get(Array, NULL, 'Participant', '1982', NULL)
#3 /var/www/html/vendor/civicrm/civicrm-core/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_participant_get(Array)
#4 /var/www/html/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(149): Civi\API\Provider\MagicFunctionProvider->invoke(Array)
#5 /var/www/html/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(81): Civi\API\Kernel->runRequest(Array)
#6 /var/www/html/vendor/civicrm/civicrm-core/api/api.php(133): Civi\API\Kernel->runSafe('Participant', 'get', Array)
Expected behaviour
The page should load as normal.
Environment information
- CiviCRM: 5.55.1
- PHP: 8.0.24
- CMS: Drupal 9.4.8
- Database: 8.0.26
- Web Server: nginx/1.20.2
Comments
We fixed this issue by switching to APIv4 so it would no longer automatically get the custom groups and fields for the participant, but this still seemed a general issue to report.
I believe an if, at line 578 after settings the variable, would fix this issue.
if ($multipleFieldGroups === NULL) {
$multipleFieldGroups = [];
}