FilamentF
Filament16mo ago
tjodalv

Problem with Import Action - Import job never completes

I am having a problem with ImportAction. I want to use it to import products from CSV file. I am testing it with CSV file that has two rows in total. But when I run the action, job keep executing endlessly over and over, spamming failed_import_rows table. I am not sure why is it doing so. If it fails to import the records is should end the job in the end. I also created custom
App\Jobs\ImportCsv
job class that extends
Filament\Actions\Imports\Jobs\ImportCsv
job class and added property
public $tries = 1;
but that doesn't work either.

If I inspect jobs table in the database I can see that the number of attempts is ridiculesly high, e.g. 15346. Then I need to stop the worker, remove the job from jobs table and clear the failed_import_rows table.

This is how I resolve records in my importer class:

public function resolveRecord(): ?Product
    {
        if (! array_key_exists('ID', $this->data) || blank($this->data['ID'])) {
            return new Product();
        }

        return Product::firstOrNew(['id' => $this->data['ID']]);
    }


Other then that I just have a bunch of columns defined on the Importer and using
afterSave()
hook to perform product stock update, as I keep stocks in separate table.

In the fail_import_rows table validation_error column is always NULL.
Was this page helpful?