CacheItemPoolDecorator does not properly handle multiple unsaved deferred items
Closed this issue · 3 comments
Bug Report
Q | A |
---|---|
Version(s) | latest |
Summary
Decorator has not valid code in commit() method (row: 284)
$this->deferred = array_unique(array_merge([], ...$notSavedItems));
$notSavedItems it is array of array<string,CacheItem>
And CacheItem do not have __toString() method. So array_unique throw Error exception.
Current behavior
"message":"Object of class Laminas\Cache\Psr\CacheItemPool\CacheItem could not be converted to string","context":{"exception":{"message":"Object of class Laminas\Cache\Psr\CacheItemPool\CacheItem could not be converted to string","code":"0","file":"/app/vendor/laminas/laminas-cache/src/Psr/CacheItemPool/CacheItemPoolDecorator.php","line":284,"extra":[],"trace":["CacheItemPoolDecorator.php(284) array_unique()",
How to reproduce
Any case when storage method
$this->storage->setItems($keyValuePair)
throw Laminas\Cache\Exception\ExceptionInterface
OR return non-empty array.
Expected behavior
No Error exception
Thanks @shandyDev!
I've reproduced a failing test and found out that this only occurs when multiple items are failing. If only one item is failing, array_unique
seems to skip anything and early returns the value.
Thats probably because why it was never detected.
Created a bugfix in #194
Thanks! I was little confused too, because I saw unit test on commit and it was somehow passed)
Very interesting behaviour but logical what array_unique() not cast to string if no elements to compare)