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

Cannot call renderPageTemplate from a console request #3124

Closed
timkelty opened this issue Jul 20, 2018 · 0 comments
Closed

Cannot call renderPageTemplate from a console request #3124

timkelty opened this issue Jul 20, 2018 · 0 comments

Comments

@timkelty
Copy link
Contributor

timkelty commented Jul 20, 2018

Description

I'm trying to call Craft::$app->getView()::renderPageTemplate or Craft::$app->getView()::renderTemplate from within a console request and an exception gets thrown:

Session does not exist in a console request

Is this expected? Craft::$app->getView()::renderTemplate does seem to work, but this is a full html doc, so renderPageTemplate seemed right.

Here's the stack trace:

2018-07-20 13:53:44 [-][-][-][error][craft\queue\QueueLogBehavior::afterError]  [10205] Generating pricelist for Kindel (attempt: 1) - Error (time: 11.049s): An exception has been thrown during the rendering of a template ("Session does not exist in a console request.").
2018-07-20 13:53:44 [-][-][-][error][Twig_Error_Runtime] craft\errors\MissingComponentException: Session does not exist in a console request. in /app/vendor/composer/craftcms/cms/src/console/Application.php:117
Stack trace:
#0 /app/vendor/composer/craftcms/cms/src/web/View.php(1418): craft\console\Application->getSession()
#1 /app/vendor/composer/craftcms/cms/src/web/View.php(854): craft\web\View->registerAssetFlashes()
#2 /app/storage/runtime/compiled_templates/86/86da71f9b2a5266b7f919c5efeb129383cc8c609eb6a3b6da9465c6ec01f6674.php(48): craft\web\View->endBody()
#3 /app/vendor/composer/twig/twig/lib/Twig/Template.php(390): __TwigTemplate_2f0c9b9d9c4e822a1c7cedd32168bd73a0621637e391cdff2df25cd9e7f2641e->doDisplay(Array, Array)
#4 /app/vendor/composer/craftcms/cms/src/web/twig/Template.php(49): Twig_Template->displayWithErrorHandling(Array, Array)
#5 /app/vendor/composer/twig/twig/lib/Twig/Template.php(367): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#6 /app/vendor/composer/craftcms/cms/src/web/twig/Template.php(31): Twig_Template->display(Array, Array)
#7 /app/storage/runtime/compiled_templates/96/9615ddaf4e28604ba3fbf6d528126f212a2012b7aa2b3a30807b815d5057184b.php(34): craft\web\twig\Template->display(Array, Array)
#8 /app/vendor/composer/twig/twig/lib/Twig/Template.php(390): __TwigTemplate_ff277ef423e2de848ede551124fdf91c1186e4a5ac24d0ae481f51ca15eabad9->doDisplay(Array, Array)
#9 /app/vendor/composer/craftcms/cms/src/web/twig/Template.php(49): Twig_Template->displayWithErrorHandling(Array, Array)
#10 /app/vendor/composer/twig/twig/lib/Twig/Template.php(367): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#11 /app/vendor/composer/craftcms/cms/src/web/twig/Template.php(31): Twig_Template->display(Array, Array)
#12 /app/vendor/composer/twig/twig/lib/Twig/Template.php(375): craft\web\twig\Template->display(Array)
#13 /app/vendor/composer/twig/twig/lib/Twig/Environment.php(289): Twig_Template->render(Array)
#14 /app/vendor/composer/craftcms/cms/src/web/View.php(330): Twig_Environment->render('_products/price...', Array)
#15 /app/vendor/composer/craftcms/cms/src/web/View.php(377): craft\web\View->renderTemplate('_products/price...', Array)
#16 /app/src/php/modules/appmodule/models/Pricelist.php(88): craft\web\View->renderPageTemplate('_products/price...', Array)
#17 /app/src/php/modules/appmodule/models/Pricelist.php(76): modules\appmodule\models\Pricelist->getProductChunk(Object(craft\elements\db\EntryQuery))
#18 /app/src/php/modules/appmodule/models/Pricelist.php(58): modules\appmodule\models\Pricelist->getProductChunks()
#19 /app/src/php/modules/appmodule/models/Pricelist.php(111): modules\appmodule\models\Pricelist->getPieces()
#20 /app/src/php/modules/appmodule/queue/jobs/GeneratePricelist.php(25): modules\appmodule\models\Pricelist->generate()
#21 /app/vendor/composer/yiisoft/yii2-queue/src/Queue.php(214): modules\appmodule\queue\jobs\GeneratePricelist->execute(Object(craft\queue\Queue))
#22 /app/vendor/composer/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('10205', 'O:46:"modules\\a...', '300', '1')
#23 /app/vendor/composer/yiisoft/yii2-queue/src/cli/Command.php(145): yii\queue\cli\Queue->execute('10205', 'O:46:"modules\\a...', '300', '1', '')
#24 [internal function]: yii\queue\cli\Command->actionExec('10205', '300', '1', '')
#25 /app/vendor/composer/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#26 /app/vendor/composer/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#27 /app/vendor/composer/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('exec', Array)
#28 /app/vendor/composer/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('exec', Array)
#29 /app/vendor/composer/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)
#30 /app/vendor/composer/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('queue/exec', Array)
#31 /app/vendor/composer/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#32 /app/vendor/composer/fusionary/craftcms-bootstrap/src/Bootstrap.php(76): yii\base\Application->run()
#33 /app/bin/craft(4): fusionary\craftcms\bootstrap\Bootstrap::run('console')
#34 {main}

Next Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Session does not exist in a console request."). in /app/src/twig/_layout/index.twig:54
Stack trace:
#0 /app/vendor/composer/craftcms/cms/src/web/twig/Template.php(49): Twig_Template->displayWithErrorHandling(Array, Array)
#1 /app/vendor/composer/twig/twig/lib/Twig/Template.php(367): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#2 /app/vendor/composer/craftcms/cms/src/web/twig/Template.php(31): Twig_Template->display(Array, Array)
#3 /app/storage/runtime/compiled_templates/96/9615ddaf4e28604ba3fbf6d528126f212a2012b7aa2b3a30807b815d5057184b.php(34): craft\web\twig\Template->display(Array, Array)
#4 /app/vendor/composer/twig/twig/lib/Twig/Template.php(390): __TwigTemplate_ff277ef423e2de848ede551124fdf91c1186e4a5ac24d0ae481f51ca15eabad9->doDisplay(Array, Array)
#5 /app/vendor/composer/craftcms/cms/src/web/twig/Template.php(49): Twig_Template->displayWithErrorHandling(Array, Array)
#6 /app/vendor/composer/twig/twig/lib/Twig/Template.php(367): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#7 /app/vendor/composer/craftcms/cms/src/web/twig/Template.php(31): Twig_Template->display(Array, Array)
#8 /app/vendor/composer/twig/twig/lib/Twig/Template.php(375): craft\web\twig\Template->display(Array)
#9 /app/vendor/composer/twig/twig/lib/Twig/Environment.php(289): Twig_Template->render(Array)
#10 /app/vendor/composer/craftcms/cms/src/web/View.php(330): Twig_Environment->render('_products/price...', Array)
#11 /app/vendor/composer/craftcms/cms/src/web/View.php(377): craft\web\View->renderTemplate('_products/price...', Array)
#12 /app/src/php/modules/appmodule/models/Pricelist.php(88): craft\web\View->renderPageTemplate('_products/price...', Array)
#13 /app/src/php/modules/appmodule/models/Pricelist.php(76): modules\appmodule\models\Pricelist->getProductChunk(Object(craft\elements\db\EntryQuery))
#14 /app/src/php/modules/appmodule/models/Pricelist.php(58): modules\appmodule\models\Pricelist->getProductChunks()
#15 /app/src/php/modules/appmodule/models/Pricelist.php(111): modules\appmodule\models\Pricelist->getPieces()
#16 /app/src/php/modules/appmodule/queue/jobs/GeneratePricelist.php(25): modules\appmodule\models\Pricelist->generate()
#17 /app/vendor/composer/yiisoft/yii2-queue/src/Queue.php(214): modules\appmodule\queue\jobs\GeneratePricelist->execute(Object(craft\queue\Queue))
#18 /app/vendor/composer/yiisoft/yii2-queue/src/cli/Queue.php(162): yii\queue\Queue->handleMessage('10205', 'O:46:"modules\\a...', '300', '1')
#19 /app/vendor/composer/yiisoft/yii2-queue/src/cli/Command.php(145): yii\queue\cli\Queue->execute('10205', 'O:46:"modules\\a...', '300', '1', '')
#20 [internal function]: yii\queue\cli\Command->actionExec('10205', '300', '1', '')
#21 /app/vendor/composer/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#22 /app/vendor/composer/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#23 /app/vendor/composer/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('exec', Array)
#24 /app/vendor/composer/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('exec', Array)
#25 /app/vendor/composer/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/exec', Array)
#26 /app/vendor/composer/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('queue/exec', Array)
#27 /app/vendor/composer/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#28 /app/vendor/composer/fusionary/craftcms-bootstrap/src/Bootstrap.php(76): yii\base\Application->run()
#29 /app/bin/craft(4): fusionary\craftcms\bootstrap\Bootstrap::run('console')
#30 {main}

Original post on SE: https://craftcms.stackexchange.com/questions/26910/how-can-i-render-a-page-template-from-a-queue-job-console-controller

@timkelty timkelty changed the title Cannot call renderPageTemplate from a console request Cannot call renderTemplate from a console request Jul 20, 2018
@timkelty timkelty changed the title Cannot call renderTemplate from a console request Cannot call renderPageTemplate from a console request Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant