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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jannakha created an issue. See original summary.

jannakha’s picture

Issue summary: View changes
jannakha’s picture

Status: Active » Needs review

All changes in MR.

vladimiraus’s picture

Assigned: jannakha » Unassigned
Status: Needs review » Reviewed & tested by the community

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);
b.ravanbakhsh’s picture

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

thanks

  • jannakha committed 1c686ccd on 8.x-2.x
    Issue #3380359: Session is not set when generating PDFs using commands (...
jannakha’s picture

Status: Reviewed & tested by the community » Fixed

merged

jsacksick’s picture

hm... This introduced phpstan errors, would have been nice to fix them before merging the MR.

jsacksick’s picture

Created an issue to fix those (See #3536590: Fix phpcs & phpstan issues).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.