TypeError: prepareItemValue() returns NULL

Created on 8 July 2025, 7 days ago

Problem/Motivation

The TypesenseClient::prepareItemValue() method is not fully type safe. I saw this error logged:

TypeError: Drupal\search_api_typesense\Api\TypesenseClient::prepareItemValue(): Return value must be of type array|string|int|float|bool, null returned in Drupal\search_api_typesense\Api\TypesenseClient->prepareItemValue() (line 961 of /modules/contrib/search_api_typesense/src/Api/TypesenseClient.php).

Steps to reproduce

I haven't been able to replicate the conditions that triggered the bug locally so I don't have more information about the circumstances that caused it. It could have been a rogue data type or processor.

In any case the bug can be replicated by calling prepareItemValue() with arguments [NULL], 'typesense_int32'.

Proposed resolution

Maybe we can harden this by throwing an exception when a passed in value does not conform to the expected type? It looks like non-array types are not handled at the moment.

Also it seems like a good idea to just filter out NULL values before calling prepareItemValue().

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇧🇬Bulgaria pfrenssen Sofia

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024