You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CsvWriterTask: a non-array input throws a TypeError when headers is null, and the task cannot run again after finalize() #241
CsvWriterTask fails with a raw TypeError on a non-array input when headers is null (default), instead of the documented \UnexpectedValueException('Input value is not an array') thrown when headers is set.
Secondary point: the task cannot be executed again after finalize(), because $this->csv is closed but not reset. This does not happen through the ProcessManager (task services are not shared, a new instance is used for each run), but it is inconsistent with CsvReaderTask, which resets it since #208.
TypeError: array_keys(): Argument #1 ($array) must be of type array, string given
Same task with headers: [a]: UnexpectedValueException: Input value is not an array (expected behaviour).
Second point: calling initialize(), execute(), proceed(), finalize() twice on the same instance throws RuntimeException: CSV file '/tmp/out.csv' was closed earlier on the second execute().
Reproduced on main (ad31c1f), PHP 8.5, Symfony 8.1, by calling the task / transformer directly. Found while adding the missing tests of #197.
Cause
CsvWriterTask::getHeaders() calls array_keys($state->getInput()) when opening the file, before getInput() validates the input.
Validate the input before reading its keys in getHeaders() (throw the same \UnexpectedValueException), and reset $this->csv to null in AbstractCsvResourceTask::finalize(). Add tests.
Activity
fix(task) #241 Fix CsvWriterTask: a non-array input throws the docume…
Merge pull request #247 from cleverage/241