ahmeda's avatar

The script tried to call a method on an incomplete object

I have an excel file containing 8K products I'm using package Laravel-excel when I upload the file just 1K of products being uploaded and then I got this error in jobs_faild table:

Error: The script tried to call a method on an incomplete object. 
Please ensure that the class definition "App\Imports\ImportProducts" 
of the object you are trying to operate on was loaded _before_ unserialize() 
gets called or provide an autoloader to load the class definition in /var/app/current/vendor/maatwebsite/excel/src/Jobs/ReadChunk.php:107

Stack trace:
#0 /var/app/current/vendor/maatwebsite/excel/src/Jobs/ReadChunk.php(107): method_exists(Object(__PHP_Incomplete_Class), 'middleware')
#1 /var/app/current/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(117): Maatwebsite\Excel\Jobs\ReadChunk->middleware()

My controller to upload the file:

public function updateOrCreateProduct(Request $request)
{
    $request->validate([
        'file' => 'required|file|mimes:xlsx,csv'
    ]);

    (new ImportProducts)->queue($request->file);

    return $this->apiRespone(success: "product updated");
}

ImportProducts file contains:

class ImportProducts implements
    ToCollection,
    WithChunkReading,
    ShouldQueue,
    WithEvents,
    SkipsEmptyRows,
    WithHeadingRow
{
    use Importable, RegistersEventListeners;

    public function collection(Collection $rows)
    {
        foreach ($rows as $row) {
            // my logic to store data to products table
        }
    }

    public function chunkSize(): int
    {
        return 100;
    }
}
0 likes
9 replies
Sinnbeck's avatar

So it works if you use less than a 100 rows? The chunk size

ahmeda's avatar

@Sinnbeck I didn’t try to make the chunk less than 100, but the file has 8k products just 1500 ones been added to products, then the error throw in jobs_failed

Sinnbeck's avatar

@Jean_ali ah sorry I misunderstood. Can you set the chuck size to a different number and see if the amount changes? Maybe 500

1 like
ahmeda's avatar
ahmeda
OP
Best Answer
Level 5

I solve the problem! I'm using AWS SQS for the queue, for some reason I just delete the old one and create a new one the queue returns to work perfectly!

FvsJson's avatar

I recreated the sqs queue but it didnt work for me...

planetfrank's avatar

I keep getting this same error, couldnt find any solution here.

Darkyn's avatar

I just ran into this a few minutes ago, and it turns out that I had just forgotten to restart the worker to load the new job class. Since the worker was caching the old one, it wasn't aware of the change.

Not sure this is your issue, but just wanted to throw it out there.

Cheers :)

1 like
lara213661's avatar

Hi! I got the same problem and same exception.

I have the following:

  • A job printing "Hello world".
  • A Controller that is dispatching the job on an existing queue called "hello-world".

I use:

  • Redis as QUEUE_DRIVER. Defined in queue.php
  • Laravel 8.0.12
  • horizon with a queue worker called supervisor-1 with "hello-world" queue. Defined in horizon.php

Solution: I solved it by using another queue. Instead of using the existing queue called "hello-world", I defined a new queue called "hello-world-2".

Question: Is this a bug getting that error and exception? Is there any better way to solve this? Restarting the worker didn't work.

2 likes
ArturHanusek's avatar

Hi Guys

it happens to me when "dispatching" code is different to worker code scenarios:

  1. you created new job and pushed, but you did not restart worker, = job gets dispatched correctly but worker is still running old code
  2. you have multiple servers running workers / web traffic = same as scenario above, job might get dispatched on server with new code but some worker server is still running old code

Please or to participate in this conversation.