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

ErrorException importing pivot model with scout #35210

Closed
cstriuli opened this issue Nov 13, 2020 · 2 comments
Closed

ErrorException importing pivot model with scout #35210

cstriuli opened this issue Nov 13, 2020 · 2 comments
Labels

Comments

@cstriuli
Copy link

  • Laravel Version: 8.8.0
  • PHP Version: 7.4.11
  • Laravel Scout Driver: algolia
  • Laravel Scout Version + Scout Extended: ^8.3

Description:

Running php artisan scout:import or php artisan scout:reimport on a Pivot Model (Illuminate\Database\Eloquent\Relations\Pivot) that implements shouldBeSearchable() generates an Exception because Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php::newQueryForCollectionRestoration (289) requires an array starting with $ids[0] and shouldBeSearchable() after filtering gives an array starting with an index greater than zero.
image

Steps To Reproduce:

I've created an fresh Laravel app with 3 models Company, Product and CompanyProductPivot + Scout with Algolia in order to reproduce the error.

  1. Clone this repo
  2. Copy the environment example
  3. Setup the algolia keys (Free Account)
  4. Run migration, seeder and queue worker
  5. Run scout:import
  6. Check the log storage/logs/laravel.log.
git clone https://github.com/cstriuli/bug-scout-import
cd bug-scout-import
composer install
cp .env.example .env 
php artisan key:generate
// update manually your Algolia keys and DB credentials
php artisan migrate --seed
php artisan queue:work
php artisan scout:import // or scout:reimport 
open storage/logs/laravel.log

Failed artisan scout:import (using shouldBeSearchable):

[2020-11-13 06:41:37] local.ERROR: Undefined offset: 0 {"exception":"[object] (ErrorException(code: 0): Undefined offset: 0 at /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php:289)
[stacktrace]
#0 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php(289): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Undefined offse...', '/Users/admin/Si...', 289, Array)
#1 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Concerns/AsPivot.php(267): Illuminate\\Database\\Eloquent\\Relations\\Pivot->newQueryForCollectionRestoration(Array)
#2 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(114): Illuminate\\Database\\Eloquent\\Relations\\Pivot->newQueryForRestoration(Array)
#3 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(73): Laravel\\Scout\\Jobs\\MakeSearchable->getQueryForModelRestoration(Object(App\\Models\\CompanyProductPivot), Array)
#4 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(56): Laravel\\Scout\\Jobs\\MakeSearchable->restoreCollection(Object(Illuminate\\Contracts\\Database\\ModelIdentifier))
#5 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(122): Laravel\\Scout\\Jobs\\MakeSearchable->getRestoredPropertyValue(Object(Illuminate\\Contracts\\Database\\ModelIdentifier))
#6 [internal function]: Laravel\\Scout\\Jobs\\MakeSearchable->__unserialize(Array)
#7 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(193): unserialize('O:33:\"Laravel\\\\S...')
#8 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(213): Illuminate\\Queue\\CallQueuedHandler->failed(Array, Object(ErrorException), 'ee250289-55a4-4...')
#9 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(192): Illuminate\\Queue\\Jobs\\Job->failed(Object(ErrorException))
#10 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(544): Illuminate\\Queue\\Jobs\\Job->fail(Object(ErrorException))
#11 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(505): Illuminate\\Queue\\Worker->failJob(Object(Illuminate\\Queue\\Jobs\\DatabaseJob), Object(ErrorException))
#12 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(433): Illuminate\\Queue\\Worker->markJobAsFailedIfWillExceedMaxAttempts('database', Object(Illuminate\\Queue\\Jobs\\DatabaseJob), 1, Object(ErrorException))
#13 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(410): Illuminate\\Queue\\Worker->handleJobException('database', Object(Illuminate\\Queue\\Jobs\\DatabaseJob), Object(Illuminate\\Queue\\WorkerOptions), Object(ErrorException))
#14 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(356): Illuminate\\Queue\\Worker->process('database', Object(Illuminate\\Queue\\Jobs\\DatabaseJob), Object(Illuminate\\Queue\\WorkerOptions))
#15 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(158): Illuminate\\Queue\\Worker->runJob(Object(Illuminate\\Queue\\Jobs\\DatabaseJob), 'database', Object(Illuminate\\Queue\\WorkerOptions))
#16 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(116): Illuminate\\Queue\\Worker->daemon('database', 'default', Object(Illuminate\\Queue\\WorkerOptions))
#17 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(100): Illuminate\\Queue\\Console\\WorkCommand->runWorker('database', 'default')
#18 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle()
#19 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#20 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#21 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#22 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Container/Container.php(596): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#23 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
#24 /Users/admin/Sites/bug-scout-import/vendor/symfony/console/Command/Command.php(258): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#25 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#26 /Users/admin/Sites/bug-scout-import/vendor/symfony/console/Application.php(920): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#27 /Users/admin/Sites/bug-scout-import/vendor/symfony/console/Application.php(266): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#28 /Users/admin/Sites/bug-scout-import/vendor/symfony/console/Application.php(142): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#29 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#30 /Users/admin/Sites/bug-scout-import/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#31 /Users/admin/Sites/bug-scout-import/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#32 {main}
"} 

Failed Queue log

image

Success artisan scout:import (without shouldBeSearchable/filtering):

image

@driesvints
Copy link
Member

Thanks, I've sent in a PR here: #35218

@driesvints
Copy link
Member

Will be in next week's release.

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

2 participants