mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/compatibility/mongodb-laravel-integration
MIT License
7k stars 1.43k forks source link

Laravel queue doesn't work with queue connection database. #2629

Closed spont4e closed 2 months ago

spont4e commented 1 year ago

Description:

Laravel queue doesn't work when mongodb is the default database driver.

Steps to reproduce

  1. Setup Laravel 10.24.0
  2. Setup mongodb/laravel-mongodb:4.0.0-rc1
  3. Change .env > DB_CONNECTION=mongodb
  4. Change .env > QUEUE_CONNECTION=database
  5. Run php8.2 artisan queue:work --queue=high,default,low --sleep=3 --tries=3 --daemon

Expected behaviour

storage/logs/laravel.log to be clean.

Actual behaviour

storage/logs/laravel.log contains error.

[2023-09-25 13:24:51] local.ERROR: Call to a member function getAttribute() on null {"exception":"[object] (Error(code: 0): Call to a member function getAttribute() on null at /var/www/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:258)
Logs: ``` [2023-09-25 13:24:51] local.ERROR: Call to a member function getAttribute() on null {"exception":"[object] (Error(code: 0): Call to a member function getAttribute() on null at /var/www/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:258) [stacktrace] #0 /var/www/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(239): Illuminate\\Queue\\DatabaseQueue->getLockForPopping() #1 /var/www/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(224): Illuminate\\Queue\\DatabaseQueue->getNextAvailableJob() #2 /var/www/vendor/mongodb/laravel-mongodb/src/Concerns/ManagesTransactions.php(101): Illuminate\\Queue\\DatabaseQueue->Illuminate\\Queue\\{closure}() #3 /var/www/vendor/mongodb/mongodb/src/Operation/WithTransaction.php(64): MongoDB\\Laravel\\Connection->MongoDB\\Laravel\\Concerns\\{closure}() #4 /var/www/vendor/mongodb/mongodb/src/functions.php(496): MongoDB\\Operation\\WithTransaction->execute() #5 /var/www/vendor/mongodb/laravel-mongodb/src/Concerns/ManagesTransactions.php(107): MongoDB\\with_transaction() #6 /var/www/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(227): MongoDB\\Laravel\\Connection->transaction() #7 /var/www/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(349): Illuminate\\Queue\\DatabaseQueue->pop() #8 /var/www/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(363): Illuminate\\Queue\\Worker->Illuminate\\Queue\\{closure}() #9 /var/www/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(163): Illuminate\\Queue\\Worker->getNextJob() #10 /var/www/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(138): Illuminate\\Queue\\Worker->daemon() #11 /var/www/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(121): Illuminate\\Queue\\Console\\WorkCommand->runWorker() #12 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle() #13 /var/www/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}() #14 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure() #15 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod() #16 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(662): Illuminate\\Container\\BoundMethod::call() #17 /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\\Container\\Container->call() #18 /var/www/vendor/symfony/console/Command/Command.php(326): Illuminate\\Console\\Command->execute() #19 /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(181): Symfony\\Component\\Console\\Command\\Command->run() #20 /var/www/vendor/symfony/console/Application.php(1081): Illuminate\\Console\\Command->run() #21 /var/www/vendor/symfony/console/Application.php(320): Symfony\\Component\\Console\\Application->doRunCommand() #22 /var/www/vendor/symfony/console/Application.php(174): Symfony\\Component\\Console\\Application->doRun() #23 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(201): Symfony\\Component\\Console\\Application->run() #24 /var/www/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle() #25 {main} "} ```
GromNaN commented 1 year ago

Do you know if it worked with Laravel 9 and laravel-mongodb 3.9? I'd like to determine whether it's a regression or a new feature or a need for documentation.

spont4e commented 1 year ago

@GromNaN I don't know... But I can test it

spont4e commented 1 year ago

@GromNaN Same problem here

Logs: ``` [2023-09-25 19:29:51] local.ERROR: Call to a member function getAttribute() on null {"exception":"[object] (Error(code: 0): Call to a member function getAttribute() on null at /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:258) [stacktrace] #0 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(239): Illuminate\\Queue\\DatabaseQueue->getLockForPopping() #1 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(224): Illuminate\\Queue\\DatabaseQueue->getNextAvailableJob() #2 /var/www/tmp/laravel/vendor/mongodb/laravel-mongodb/src/Concerns/ManagesTransactions.php(102): Illuminate\\Queue\\DatabaseQueue->Illuminate\\Queue\\{closure}() #3 /var/www/tmp/laravel/vendor/mongodb/mongodb/src/Operation/WithTransaction.php(64): Jenssegers\\Mongodb\\Connection->Jenssegers\\Mongodb\\Concerns\\{closure}() #4 /var/www/tmp/laravel/vendor/mongodb/mongodb/src/functions.php(496): MongoDB\\Operation\\WithTransaction->execute() #5 /var/www/tmp/laravel/vendor/mongodb/laravel-mongodb/src/Concerns/ManagesTransactions.php(108): MongoDB\\with_transaction() #6 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(227): Jenssegers\\Mongodb\\Connection->transaction() #7 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(342): Illuminate\\Queue\\DatabaseQueue->pop() #8 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(351): Illuminate\\Queue\\Worker->Illuminate\\Queue\\{closure}() #9 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(160): Illuminate\\Queue\\Worker->getNextJob() #10 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(148): Illuminate\\Queue\\Worker->daemon() #11 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(131): Illuminate\\Queue\\Console\\WorkCommand->runWorker() #12 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle() #13 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Container/Util.php(41): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}() #14 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure() #15 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod() #16 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(661): Illuminate\\Container\\BoundMethod::call() #17 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\\Container\\Container->call() #18 /var/www/tmp/laravel/vendor/symfony/console/Command/Command.php(291): Illuminate\\Console\\Command->execute() #19 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(153): Symfony\\Component\\Console\\Command\\Command->run() #20 /var/www/tmp/laravel/vendor/symfony/console/Application.php(1014): Illuminate\\Console\\Command->run() #21 /var/www/tmp/laravel/vendor/symfony/console/Application.php(301): Symfony\\Component\\Console\\Application->doRunCommand() #22 /var/www/tmp/laravel/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun() #23 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Console/Application.php(102): Symfony\\Component\\Console\\Application->run() #24 /var/www/tmp/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(155): Illuminate\\Console\\Application->run() #25 /var/www/tmp/laravel/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle() #26 {main} "} ```
GromNaN commented 11 months ago

Tracked in PHPORM-87 (duplicated in PHPORM-97)

devjeet073 commented 8 months ago

@spont4e Have you checked file "config/queue.php".

Make sure in "connections"->"database"->["driver"=> "mongodb"].

spont4e commented 7 months ago

@spont4e Have you checked file "config/queue.php".

Make sure in "connections"->"database"->["driver"=> "mongodb"].

Yes, Everything was configured properly.

Nemutagk commented 6 months ago

is there any new news about this, we are already in laravel 11 and the error still persists when the default connection is MongoDB.

bisht2050 commented 6 months ago

We tentatively plan to work on this in the next month (April 2024).

GustavoLC901010 commented 2 months ago

Hello!! Any news?

bisht2050 commented 2 months ago

This was part of the 4.3 release. https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/queues/