When using Views Data Export, and the `$data` array contains only a message, the following error is thrown:
`TypeError: Argument 1 passed to League\Csv\Writer::insertOne() must be of the type array, string given, called in /var/www/argonne-insideout.local/docroot/modules/contrib/csv_serialization/src/Encoder/CsvEncoder.php on line 158 in League\Csv\Writer->insertOne() (line 151 of /var/www/argonne-insideout.local/vendor/league/csv/src/Writer.php).`
This is related to #2975802: Undefined offset: 0 in Drupal\csv_serialization\Encoder\CsvEncoder->extractHeaders(), and a similar patch was used to fix this error. However, it seems like this condition should be checked before attempting to encode to CSV.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3120645-10.patch | 1.56 KB | acbramley |
| #10 | 3120645-10-failing-test.patch | 1.05 KB | acbramley |
Comments
Comment #2
byrond commentedComment #3
steinmb commentedComment #4
Bagz commentedCame across this same issue on 8.x-2.0-beta3, thanks for the patch.
Comment #5
tjtj commentedThis is also happening in 9.1.4.
Message TypeError: Argument 1 passed to League\Csv\Writer::insertOne() must be of the type array, string given, called in /home/briarcli/public_html/web/modules/contrib/csv_serialization/src/Encoder/CsvEncoder.php on line 159 in League\Csv\Writer->insertOne() (line 140 of /home/briarcli/public_html/vendor/league/csv/src/Writer.php)Does this patch work?
Comment #6
tjtj commentedThe patch does work in 9.1.4. Why isn't it incorrporated in the distro? People spand a lot of time chasing down patches!
Comment #7
grasmash commentedComment #9
acbramley commentedThis will still be true if $data is a string
Comment #10
acbramley commentedThe bug wasn't when
$datawasn't an array (that's actually taken care of at the top of the function), but when$rowwasn't. This patch fixes it with a test, however automated tests need to be set up for 2.x and the decoding test seems to be failing.Comment #11
steinmb commentedI think your right. I also noticed in
CsvEncoder::flattenCellcontain a call similar to this.Line
$cell_value .= '|' . $this->flattenCell($item);it calls it self, but when the array you unpack contain a string item, booom!Comment #13
grasmash commented