Session is not set when generating PDFs using commands (eg queue workers)

Created on 10 August 2023, over 1 year ago
Updated 17 August 2023, over 1 year ago

Problem/Motivation

When generating PDFs via browser - request and session are set and are not null.
When generating PDFs via command on server side (eg via drush command or queue worker - to prevent timeout on HUGE PDFs) - request and session are not set which results in "Session not set exception" and process fails to generated PDF.

Steps to reproduce

Run PDF generation without session (as a command).

Proposed resolution

Check if session exists, if not create a new session

Remaining tasks

create patch

User interface changes

none

API changes

none

Data model changes

none

🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

🇦🇺Australia jannakha Brisbane!

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jannakha
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    54 pass
  • @jannakha opened merge request.
  • 🇦🇺Australia jannakha Brisbane!
  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia jannakha Brisbane!

    All changes in MR.

  • Issue was unassigned.
  • Status changed to RTBC over 1 year ago
  • 🇦🇺Australia VladimirAus Brisbane, Australia

    Patch applied and no more Session is not set. error when running the following code during the drush queue:run.

          $session_handler = \Drupal::service('session_handler.write_safe');
          $this->accountSwitcher->switchTo(new UserSession(['uid' => 1]));
          $session_handler->setSessionWritable(TRUE);
    ...
            // Generate PDF (new instance of engine required).
            $print_engine = $this->entityPrintPluginManager->createSelectedInstance('pdf');
            $this->printBuilder->savePrintable([$node], $print_engine, $scheme, $location, TRUE, $view_mode);
    
  • 🇦🇺Australia b.ravanbakhsh Adelaide

    patch applied and fixed the error in our `drush cron`

    thanks

Production build 0.71.5 2024