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

Queue SerializesAndRestoresModelIdentifiers id column name doesnt exist #42978

Closed
HthSolid opened this issue Jun 27, 2022 · 4 comments
Closed

Comments

@HthSolid
Copy link

  • Laravel Version: 9.17.0
  • PHP Version: 8.1.7
  • Database Driver & Version: mysql , MariaDB 10.1.48-MariaDB-0+deb9u2

Description:

When you call a get() in eloquent DB with a wherein outside of a queue, then use the results inside of a queue with a custom id column name like "sotb_id" that is not "id" and doesnt have a column named "id", the SerializesAndRestoresModelIdentifiers.php from vendor\laravel\framework\src\Illuminate\Queue
will translate it inside of the queue to call the id column which in this table doesnt exist and therefore will cause an error.

Steps To Reproduce:

Outside function:
$myList = SomeTable::whereIn('sotb_id', $myListofIDs)->where('is_something', 0)->where('is_else', 0)->select('sotb_id', 'some_info')->get();
myQueue::dispatch($myList)

Inside Queue: App/Jobs/VerifyJob.php

foreach($this->myList as $key => $value) {
//something
}

Detailed Error:

[2022-06-27 15:35:38] production.CRITICAL: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sometable.id' in 'where clause' (SQL: select * from sometable where sometable.id in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?))
[2022-06-27 15:35:38] production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sometable.id' in 'where clause' (SQL: select * from sometable where sometable.id in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) {"exception":"[object] (Illuminate\Database\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sometable.id' in 'where clause' (SQL: select * from sometable where sometable.id in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) at /httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:742)
[stacktrace]
#0 /httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(702): Illuminate\Database\Connection->runQueryCallback()
#1 /httpdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(404): Illuminate\Database\Connection->run()
#2 /httpdocs/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2630): Illuminate\Database\Connection->select()
#3 /httpdocs/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2618): Illuminate\Database\Query\Builder->runSelect()
#4 /httpdocs/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3154): Illuminate\Database\Query\Builder->Illuminate\Database\Query\{closure}()
#5 /httpdocs/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2619): Illuminate\Database\Query\Builder->onceWithColumns()
#6 /httpdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(698): Illuminate\Database\Query\Builder->get()
#7 /httpdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(682): Illuminate\Database\Eloquent\Builder->getModels()
#8 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(74): Illuminate\Database\Eloquent\Builder->get()
#9 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(56): App\Jobs\VerifyEmailJob->restoreCollection()
#10 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(126): App\Jobs\VerifyEmailJob->getRestoredPropertyValue()
#11 [internal function]: App\Jobs\VerifyJob->__unserialize()
#12 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(96): unserialize()
#13 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(59): Illuminate\Queue\CallQueuedHandler->getCommand()
#14 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call()
#15 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(428): Illuminate\Queue\Jobs\Job->fire()
#16 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(378): Illuminate\Queue\Worker->process()
#17 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(172): Illuminate\Queue\Worker->runJob()
#18 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(130): Illuminate\Queue\Worker->daemon()
#19 /httpdocs/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(114): Illuminate\Queue\Console\WorkCommand->runWorker()
#20 /httpdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Queue\Console\WorkCommand->handle()
#21 /httpdocs/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#22 /httpdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#23 /httpdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#24 /httpdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\Container\BoundMethod::call()
#25 /httpdocs/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call()
#26 /httpdocs/vendor/symfony/console/Command/Command.php(308): Illuminate\Console\Command->execute()
#27 /httpdocs/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run()
#28 /httpdocs/vendor/symfony/console/Application.php(998): Illuminate\Console\Command->run()
#29 /httpdocs/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand()
#30 /httpdocs/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#31 /httpdocs/vendor/laravel/framework/src/Illuminate/Console/Application.php(102): Symfony\Component\Console\Application->run()
#32 /httpdocs/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run()
#33 /httpdocs/artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#34 {main}

@driesvints
Copy link
Member

Is your $primaryKey property on your model set to sotb_id?

@HthSolid
Copy link
Author

I tried with and without, it didnt change

@driesvints
Copy link
Member

Heya, thanks for reporting.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as separate commits on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@driesvints
Copy link
Member

Will re-open once a repo is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants