mongodb / laravel-mongodb

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

Call to a member function beginTransaction() on null #964

Closed sachinvrg closed 6 years ago

sachinvrg commented 8 years ago

When I fire php artisan queue:work command , it throws following error PHP Fatal error: Call to a member function beginTransaction() on null in /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 576 PHP Stack trace: PHP 1. {main}() /var/www/html/push_admin/setupl/artisan:0 PHP 2. Illuminate\Foundation\Console\Kernel->handle() /var/www/html/push_admin/setupl/artisan:36 PHP 3. Symfony\Component\Console\Application->run() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:107 PHP 4. Symfony\Component\Console\Application->doRun() /var/www/html/push_admin/setupl/vendor/symfony/console/Application.php:117 PHP 5. Symfony\Component\Console\Application->doRunCommand() /var/www/html/push_admin/setupl/vendor/symfony/console/Application.php:186 PHP 6. Illuminate\Console\Command->run() /var/www/html/push_admin/setupl/vendor/symfony/console/Application.php:794 PHP 7. Symfony\Component\Console\Command\Command->run() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Console/Command.php:155 PHP 8. Illuminate\Console\Command->execute() /var/www/html/push_admin/setupl/vendor/symfony/console/Command/Command.php:256 PHP 9. Illuminate\Container\Container->call() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Console/Command.php:169 PHP 10. call_user_func_array:{/var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Container/Container.php:507}() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Container/Container.php:507 PHP 11. Illuminate\Queue\Console\WorkCommand->fire() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Container/Container.php:507 PHP 12. Illuminate\Queue\Console\WorkCommand->runWorker() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:79 PHP 13. Illuminate\Queue\Worker->pop() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:126 PHP 14. Illuminate\Queue\Worker->getNextJob() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:149 PHP 15. Illuminate\Queue\DatabaseQueue->pop() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:180 PHP 16. Illuminate\Database\Connection->beginTransaction() /var/www/html/push_admin/setupl/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:162

[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function beginTransaction() on null

Anybody have any idea about it? Please help!!!

sachinvrg commented 8 years ago

Also posted question on stack overflow http://stackoverflow.com/questions/39615770/php-fatal-error-call-to-a-member-function-begintransaction-on-null-in-connect

parth-vora-7 commented 8 years ago

Hello,

I'm also getting this same error.

[2016-11-12 20:18:45] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function beginTransaction() on null' in C:\wamp\www\blog\vendor\laravel\framework\src\Illuminate\Database\Connection.php:611 Stack trace:

0 {main}

Can anybody please help me?

Thanks,

parth-vora-7 commented 8 years ago

@sachinvrg , Have you configured queue properly as described over here: https://github.com/jenssegers/laravel-mongodb#queues

I have found the issue with my project. I had not followed the queue configuration of the package. Just follow the proper instruction and it works very well.

janhartigan commented 7 years ago

The specific issue that it's complaining about is that it's trying to get the PDO on a database connection that doesn't have it.

https://github.com/laravel/framework/blob/d1a4f3fc7951c04ff91855511ed8c73b1a98e533/src/Illuminate/Database/Connection.php#L612

The getPdo() method returns null in the case of the mongodb driver connection. You may have to avoid using the database queue driver if you use this package, or you can overload the beginTransaction method to simply do nothing.

ahkui commented 6 years ago

override this in authcontroller protected function incrementLoginAttempts(Request $request){}

prashant-pokhriyal commented 5 years ago

@janhartigan , where to overload beginTransaction method?

phillmorgan28 commented 5 years ago

Having this issue on Laravel 5.8 (latest) when attempting to connect through API.

`Call to a member function beginTransaction() on null {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Call to a member function beginTransaction() on null at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:109) [stacktrace]

0 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php(93): Illuminate\Database\Connection->createTransaction()

1 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php(23): Illuminate\Database\Connection->beginTransaction()

2 /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/DatabaseStore.php(183): Illuminate\Database\Connection->transaction(Object(Closure))

3 /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/DatabaseStore.php(122): Illuminate\Cache\DatabaseStore->incrementOrDecrement('97ae145b1055ad7...', 1, Object(Closure))

4 /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(331): Illuminate\Cache\DatabaseStore->increment('97ae145b1055ad7...', 1)

5 /var/www/html/vendor/laravel/framework/src/Illuminate/Cache/RateLimiter.php(65): Illuminate\Cache\Repository->increment('97ae145b1055ad7...')

6 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(56): Illuminate\Cache\RateLimiter->hit('97ae145b1055ad7...', 60)

7 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Routing\Middleware\ThrottleRequests->handle(Object(Illuminate\Http\Request), Object(Closure), 60, '1')

8 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

9 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

10 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(682): Illuminate\Pipeline\Pipeline->then(Object(Closure))

11 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(657): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))

12 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(623): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))

13 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(612): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

14 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))

15 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))

16 /var/www/html/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

17 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))

18 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

19 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

20 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))

21 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

22 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

23 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))

24 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

25 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

26 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))

27 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

28 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(62): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

29 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(163): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))

30 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

31 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

32 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))

33 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))

34 /var/www/html/public/index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))`

gideonpeters commented 4 years ago

@phillmorgan28 did you eventually resolve this?

umimehar commented 4 years ago

Anyone solved this problem? i am not using queue.

paouriel commented 4 years ago

This issue still persists. I've already configured my queue.php according here: Laravel MongoDB Queues

Already ran php artisan config:cache and this are the values for my queue.php

config('queue.connections.database') ```js [ "driver" => "mongodb", "table" => "jobs", "queue" => "default", "retry_after" => 90, ] ```
config('queue.failed') ```js [ "driver" => "mongodb", "database" => "mongodb", "table" => "failed_jobs", ] ```

Any other fix for this?

divine commented 4 years ago

This issue still persists. I've already configured my queue.php according here: Laravel MongoDB Queues

Already ran php artisan config:cache and this are the values for my queue.php

config('queue.connections.database')

[
     "driver" => "mongodb",
     "table" => "jobs",
     "queue" => "default",
     "retry_after" => 90,
]

config('queue.failed')

[
     "driver" => "mongodb",
     "database" => "mongodb",
     "table" => "failed_jobs",
]

Any other fix for this?

@paouriel can't recreate, check that you've correct mongodb settings, probably you're not even connecting to db.

paouriel commented 4 years ago

@divine I managed to create a workaround for this. I've created a temporary command. Here: Laravel MongoDB Transaction Fix

divine commented 4 years ago

@divine I managed to create a workaround for this. I've created a temporary command. Here: Laravel MongoDB Transaction Fix

This is really bad practice to modify vendor files. As I've said can't really recreate it.

Fork this library https://github.com/Smolevich/demo-mongo-application and add configuration as well as examples so it will be easy to recreate issues you're having.

wajdijurry commented 3 years ago

Any solution for this headache issue ?

wajdijurry commented 3 years ago

The specific issue that it's complaining about is that it's trying to get the PDO on a database connection that doesn't have it.

https://github.com/laravel/framework/blob/d1a4f3fc7951c04ff91855511ed8c73b1a98e533/src/Illuminate/Database/Connection.php#L612

The getPdo() method returns null in the case of the mongodb driver connection. You may have to avoid using the database queue driver if you use this package, or you can overload the beginTransaction method to simply do nothing.

Explain more please

robertoarruda commented 3 years ago

The problem still exists. @jenssegers, please reopen this issue.

divine commented 3 years ago

The problem still exists. @jenssegers, please reopen this issue.

See https://github.com/jenssegers/laravel-mongodb/pull/1904

Thanks!