SpartnerNL / Laravel-Excel

🚀 Supercharged Excel exports and imports in Laravel
https://laravel-excel.com
MIT License
12.28k stars 1.92k forks source link

[Bug]: SkipsFailures doesn't seem to work with WithChunkReading #4150

Closed jargoud closed 1 month ago

jargoud commented 4 months ago

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

What version of Laravel Excel are you using?

3.1.55

What version of Laravel are you using?

10.48.7

What version of PHP are you using?

8.3.8

Describe your issue

When using both SkipsFailures trait and WithChunkReading interface, it seems that only the chunk import instance failures collection is populated, not the original import one, which means it isn't possible to execute a code similar to the one from the documentation:

$import = new UsersImport();
$import->import('users.xlsx');

foreach ($import->failures() as $failure) {
     $failure->row(); // row that went wrong
     $failure->attribute(); // either heading key (if using heading row concern) or column index
     $failure->errors(); // Actual error messages from Laravel validator
     $failure->values(); // The values of the row that has failed.
}

In the above example, $import->failures() will always be empty.

How can the issue be reproduced?

class MyImport implements SkipsOnFailure, WithChunkReading, WithValidation
{
    use SkipsFailures;

    public function rules(): array
    {
        return [
            ['required', 'numeric'],
        ];
    }

    public function chunkSize(): int
    {
        return 100;
    }
}

What should be the expected behaviour?

It'd be great to have a way to populate failures in the import instance.

WilliamSauvan commented 3 months ago

I'm interested on a way to solve this issue, I confirm that imports with chunk and skiponfailure have no way to easily gather failures

stale[bot] commented 1 month ago

This bug report has been automatically closed because it has not had recent activity. If this is still an active bug, please comment to reopen. Thank you for your contributions.