Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking CSV for headers when malformed results in 502 #1397

Open
jrrdnx opened this issue Jan 8, 2024 · 0 comments
Open

Checking CSV for headers when malformed results in 502 #1397

jrrdnx opened this issue Jan 8, 2024 · 0 comments
Labels

Comments

@jrrdnx
Copy link

jrrdnx commented Jan 8, 2024

Bit of a different issue here since I already know the cause.

Had a client provide a CSV file that resulted in a 502 when first setting up the feed. We could provide the Name, Feed URL, Type, etc, but a 502 resulted when hitting Save & Continue and it first tried parsing the file for headers. In our case, there were a couple instances of multiple columns in the header row with the exact same name: Address and Address instead of Address and Address 2.

Not sure if it's possible to resolve in Feed Me or if this is more an issue for league/csv, but maybe some errors could be thrown in

private function _getRows($reader): mixed
{
// We try to first fetch the first row in the CSV which we figure is the headers. But if it's not
// it'll throw an error saying the first row of the CSV isn't valid, and not unique, etc.
// So, in that case, just fail silently, and move on to the 'traditional' method which are just numbers.
//
// You really should provide your CSVs with headers though.
// Support for league/csv v8 with a header
try {
return $reader->fetchAssoc(0);
} catch (Throwable $e) {
}
// Support for league/csv v8 without a header
try {
return $reader->fetch();
} catch (Throwable $e) {
}
$stmt = Statement::create();
// Support for league/csv v9 with a header
try {
$reader->setHeaderOffset(0);
return $stmt->process($reader);
} catch (Throwable $e) {
}
// Support for league/csv v9 without a header
$reader->setHeaderOffset(null);
return $stmt->process($reader);
}
instead of failing silently.

Additional info

  • Craft version: Pro 4.5.14
  • PHP version: 8.2.7
  • Database driver & version: MySQL 8.0.27
  • Plugins & versions: Feed Me 5.3.0
@jrrdnx jrrdnx added the bug label Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant