Description
GetTask and SetTask merge their input over their options (array_merge) after the options have been resolved: the values coming from the input (adapter, key, value) are never validated by the options resolver. An invalid type is not reported as an invalid option and the task fails later with an unrelated error:
- a non-string
adapter triggers a \TypeError from AdapterRegistry::getAdapter();
- a non-string
key is passed to the cache adapter as is (Psr\Cache\InvalidArgumentException from the adapter, or a \TypeError, depending on the adapter).
Reproduction
demo.cache.set_invalid_input_option in process-bundle-demo:
clever_age_process:
configurations:
demo.cache.set_invalid_input_option:
tasks:
item:
service: '@CleverAge\ProcessBundle\Task\ConstantOutputTask'
options:
output:
adapter: 1
key: 'key1'
value: 'value1'
outputs: [set]
set:
service: '@CleverAge\CacheProcessBundle\Task\SetTask'
options:
adapter: 'memory'
key: '' # Overridden by the input
value: ~ # Overridden by the input
$ bin/console cleverage:process:execute demo.cache.set_invalid_input_option
In AdapterRegistry.php line 38:
CleverAge\CacheProcessBundle\Registry\AdapterRegistry::getAdapter(): Argument #1 ($code) must be of type string, int given, called in /var/www/vendor/cleverage/cache-process-bundle/src/Task/SetTask.php on line 38
Expected: an InvalidOptionsException, e.g. The option "adapter" with value 1 is expected to be of type "string", but is of type "int".
Tested on main (f5e8bb2), cleverage/process-bundle 5.1, PHP 8.5, Symfony 7.4.
Cause
AbstractCacheTask::getMergedOptions() merges the raw input over the options resolved by AbstractConfigurableTask::getOptions().
Proposed fix
In getMergedOptions(), resolve the options merged with the input keys matching a defined option (the other input keys stay ignored, as documented). Replace the note "The values coming from the input are not validated by the options resolver" in get_task.md and set_task.md.
Out of scope: adapter / key / value still have to be set at configuration level, and a placeholder key: '' not overridden by the input still fails with the adapter Psr\Cache\InvalidArgumentException (to be discussed separately).
Requirements
Breaking changes
None for valid inputs. An input giving an option value of an invalid type already made the task fail (or passed an invalid key to the adapter), it now fails with an InvalidOptionsException.
Description
GetTaskandSetTaskmerge their input over their options (array_merge) after the options have been resolved: the values coming from the input (adapter,key,value) are never validated by the options resolver. An invalid type is not reported as an invalid option and the task fails later with an unrelated error:adaptertriggers a\TypeErrorfromAdapterRegistry::getAdapter();keyis passed to the cache adapter as is (Psr\Cache\InvalidArgumentExceptionfrom the adapter, or a\TypeError, depending on the adapter).Reproduction
demo.cache.set_invalid_input_optionin process-bundle-demo:Expected: an
InvalidOptionsException, e.g.The option "adapter" with value 1 is expected to be of type "string", but is of type "int".Tested on
main(f5e8bb2), cleverage/process-bundle 5.1, PHP 8.5, Symfony 7.4.Cause
AbstractCacheTask::getMergedOptions()merges the raw input over the options resolved byAbstractConfigurableTask::getOptions().Proposed fix
In
getMergedOptions(), resolve the options merged with the input keys matching a defined option (the other input keys stay ignored, as documented). Replace the note "The values coming from the input are not validated by the options resolver" inget_task.mdandset_task.md.Out of scope:
adapter/key/valuestill have to be set at configuration level, and a placeholderkey: ''not overridden by the input still fails with the adapterPsr\Cache\InvalidArgumentException(to be discussed separately).Requirements
Breaking changes
None for valid inputs. An input giving an option value of an invalid type already made the task fail (or passed an invalid key to the adapter), it now fails with an
InvalidOptionsException.