esmero / strawberryfield

A Field of strawberries
GNU Lesser General Public License v3.0
10 stars 5 forks source link

Deprecation error: "trim" receiving NULL #300

Closed patdunlavey closed 6 months ago

patdunlavey commented 7 months ago

Seeing a lot of these messages while indexing content:

Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in 
Drupal\strawberryfield\Plugin\DataType\StrawberryValuesFromJson->process() (line 76 of  
/var/www/html/web/modules/contrib/strawberryfield/src/Plugin/DataType/StrawberryValuesFromJson.php)

https://github.com/esmero/strawberryfield/blob/8a31b805363409e3dde4e7ec11b4dd0dd12d780e/src/Plugin/DataType/StrawberryValuesFromJson.php#L76

It presumes that every value in the array $flattened[$needle] is a string, where evidently that may not be the case.

Is the fix for this to simply catch cases where the value is null and either remove it, or convert it to an empty string? Or is this indicative of a condition that should not occur?

DiegoPino commented 7 months ago

Hi, thanks for reporting. Give me a few minutes to debug, we have plenty of archipelago's running this code base without erroring and since i was sure (no longer) i had fixed all trims i saw in November i want to be sure there is not another issue somewhere. Will report back in 30 min with a fix. Thanks!

DiegoPino commented 7 months ago

@patdunlavey ok. It does not hurt to check for a null before trimming or even better, only trim strings. In my memory the flattener would had already dealt with empty values but seems like it is not. I will check if this is also a behavior that happens somewhere else. Pull coming in 15. Thanks

DiegoPino commented 6 months ago

Fixed via https://github.com/esmero/strawberryfield/commit/3300fe6fd719b364a060d72808367a3dfe61f2ed and https://github.com/esmero/strawberryfield/commit/8b47244c79f51e3a6b49694bd6073ac67a4bd095