-
Notifications
You must be signed in to change notification settings - Fork 4
Description
π Bug: element_children() error in flattenKeys() on scalar keyword input
Project: search_api_solr
Backdrop CMS version: 1.x (tested on 1.27.2)
Module version: 1.x (latest dev)
Search backend: OpenSolr (hosted Solr service)
Summary
When performing certain keyword searches, this module throws a fatal error:
User error: "0" is an invalid render array key in element_children()
in element_children() (line 7548 of core/includes/common.inc)
The error occurs in the method SearchApiSolrService::flattenKeys() in includes/service.inc. It incorrectly assumes that $keys is a render array and passes it to element_children(), even though $keys may contain scalars with numeric keys.
Steps to Reproduce
- Configure a Solr server using OpenSolr.
- Create a Search API index and attach it to a View.
- Add a fulltext keyword filter to the View.
- Perform a keyword search using a simple word (e.g.,
christmas).
In some cases, the $keys array passed into flattenKeys() looks like this:
[
0 => 'christmas',
'#conjunction' => 'OR',
]This causes element_children() to throw an error, as 0 => 'christmas' is not a valid child in a render array.
Why This Happens
The function element_children() is only intended for render arrays. Here, $keys is just a structured array of search conditions and not meant for rendering. Calling element_children() on such data will break when numeric or scalar values are included.
Proposed Fix
Replace this line:
foreach (element_children($keys) as $i) {With this:
foreach ($keys as $i => $key) {
if (strpos($i, '#') === 0) {
continue; // Skip metadata keys like #conjunction
}This change avoids element_children() entirely, filters metadata manually, and is safe for scalar/non-render values.
Patch
A working patch is attached below:
β
Prevents the error
β
Keeps all original behavior
β
Safe for scalar + nested array input
Recommendation
- β
Consider removing all usage of
element_children()on non-render data for future robustness. - π This issue is exposed by OpenSolr, but the underlying logic bug could affect any site given the right input structure.
π Patch File (Download)
Patch file is attached