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

'Call to a member function getUniqueId() on a non-object' when running two console commands at once #10028

Open
olleharstedt opened this issue Oct 27, 2015 · 13 comments
Labels
type:docs Documentation

Comments

@olleharstedt
Copy link

Hi!

I get this error when trying to run two console jobs at once:

root@-3://yii2# php yii cron & php yii cron & wait
[1] 5532
[2] 5533
PHP Fatal error:  Call to a member function getUniqueId() on a non-object in /yii2/vendor/yiisoft/yii2/base/Controller.php on line 318
PHP Fatal Error 'yii\base\ErrorException' with message 'Call to a member function getUniqueId() on a non-object'

in /yii2/vendor/yiisoft/yii2/base/Controller.php:318

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
[1]-  Done                    php yii cron
[2]+  Exit 255                php yii cron

The line that fails is this:

return $this->module instanceof Application ? $this->id : $this->module->getUniqueId() . '/' . $this->id;

So obviously there is no module in my application. Bug or configuration error?

The console command runs fine when only running one at a time. But I need to make sure there won't be any race conditions.

Grateful for any help.

@samdark
Copy link
Member

samdark commented Oct 27, 2015

Weird.

@olleharstedt
Copy link
Author

Yeah. :) Can you reproduce?

@samdark
Copy link
Member

samdark commented Oct 27, 2015

No.

@ghost
Copy link

ghost commented Feb 21, 2016

I'm having exactly the same issue, but with web Controller and in 100% of cases. My situation is a bit more complicated - I have app on Yii1 and I'm trying to add Yii2 as hybrid. Yii1 controllers works fine, but single Yii2 controller fails with the same error in the same line.

I have only Yii2 controller, no models or views and it looks super simple:

use yii\web\Controller;

class InvoiceController extends Controller
{

    public function actionIndex()
    {
        print 123;
        \Yii::$app->end();
        return $this->render('index');
    }
}

Do I have any options?

@cebe
Copy link
Member

cebe commented Feb 22, 2016

@EvgeniySpinovSell what is the output of var_dump(\Yii::$app) when you add that to getUniqueId() method in controller?

@ghost
Copy link

ghost commented Feb 22, 2016

@cebe
Thank you for your prompt reply.
Here you go:

Yii_app.txt

@cebe
Copy link
Member

cebe commented Feb 22, 2016

that is weird, how did you create the controller?

@ghost
Copy link

ghost commented Feb 22, 2016

I've created the folder "controllers", created file mentioned above.

Added route to an controllerMap in the config of yii1, so the request would be routed to a proper controller, like this:

'invoice' => [ 'class' => 'webroot.controllers.InvoiceController' ],

and rule to url manager so it won't do default processing for this module, instead, just proceed with <controller>/<action>

Then I call in browser:
http://url/invoice/index

@ghost
Copy link

ghost commented Feb 22, 2016

And just to clarify the thing: I've added var_dump() which I've attached to a yii2\web\Controller class itself ( i.e. modified framework controller to get a dump ), cause adding the function to my controller won't make it working, cause it won't reach it.

Proof:

[Sat Feb 13 20:38:03.166892 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP Fatal error:  Call to a member function getUniqueId() on a non-object in /var/www/html/crm/vendor/yiisoft/yii2/base/Controller.php on line 325
[Sat Feb 13 20:38:03.166905 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP Stack trace:
[Sat Feb 13 20:38:03.166920 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP   1. {main}() /var/www/html/crm/index.php:0
[Sat Feb 13 20:38:03.166935 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP   2. CApplication->run() /var/www/html/crm/index.php:75
[Sat Feb 13 20:38:03.166950 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP   3. CWebApplication->processRequest() /var/www/html/crm/framework/base/CApplication.php:169
[Sat Feb 13 20:38:03.166965 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP   4. CWebApplication->runController() /var/www/html/crm/framework/web/CWebApplication.php:141
[Sat Feb 13 20:38:03.166980 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP   5. yii\\base\\Controller->run() /var/www/html/crm/framework/web/CWebApplication.php:282
[Sat Feb 13 20:38:03.166995 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP   6. yii\\base\\Controller->runAction() /var/www/html/crm/vendor/yiisoft/yii2/base/Controller.php:185
[Sat Feb 13 20:38:03.167010 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP   7. yii\\base\\Action->getUniqueId() /var/www/html/crm/vendor/yiisoft/yii2/base/Controller.php:129
[Sat Feb 13 20:38:03.167025 2016] [:error] [pid 27309] [client 192.168.56.1:58609] PHP   8. yii\\base\\Controller->getUniqueId() /var/www/html/crm/vendor/yiisoft/yii2/base/Action.php:70

@cebe
Copy link
Member

cebe commented Feb 22, 2016

seems like you want to use a yii2 controller in the yii1 routing process. This does not work because controllers in yii2 are created differently from yii1.

@ghost
Copy link

ghost commented Feb 22, 2016

This is exactly my impression, but how would I add Yii2 code to a Yii1 project? According to migration guide published on Yii2 site, which I've followed, it should be possible by modifying entry point and configs.

@cebe
Copy link
Member

cebe commented Feb 22, 2016

you can not mix yii1 and yii2 controllers in one app. If you run the Yii2 application, you need to use yii2 controllers, if you run the Yii1 application, you need to use yii1 controllers.

@ghost
Copy link

ghost commented Feb 22, 2016

This is actually a very valuable feedback cause it's not mentioned anywhere. Probably you should state this in the guide. Thank you for your help, won't offtopic here anymore, cause my issue have a different root as figured.

@olleharstedt olleharstedt changed the title 'Call to a member function getUniqueId() on a non-object' when running to console commands at once 'Call to a member function getUniqueId() on a non-object' when running two console commands at once Feb 23, 2016
@cebe cebe added the type:docs Documentation label Mar 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:docs Documentation
Projects
None yet
Development

No branches or pull requests

3 participants