Problem/Motivation

When send a request of SUB_REQUEST type $this->requestStack->getCurrentRequest()->getSession() returns NULL and therefore we get an error trying to call function get() on NULL.
From Session::handle() method: session is set only for MASTER_REQUEST type requests.
:handle() function

Drupal core version: 9.4.8
Autologout module version: 8.x-1.4

Error message
Error: Call to a member function get() on null in Drupal\autologout\EventSubscriber\AutologoutSubscriber->onRequest() (line 123 of modules/contrib/autologout/src/EventSubscriber/AutologoutSubscriber.php)

Steps to reproduce

  • Find any usage of sub request (e.g. search for ->handle($subrequest, HttpKernelInterface::SUB_REQUEST)) and try to send this request so it would lead to AutologoutSubscriber::onRequest() method and cause the issue
  • OR
  • Install Ctools module
  • Install Layout builder library module OR any other module that allows to add conditions(e.g. pathauto_condition_ui provided by pathauto module
  • try to add a condition on Manage conditions page manage conditions page

Issue fork autologout-3328196

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

sergey.semchuk created an issue. See original summary.

sergey.semchuk’s picture

PHP 7 patch

sergey.semchuk’s picture

PHP 8 patch

sergey.semchuk’s picture

Status: Active » Needs review
the_g_bomb’s picture

Failing because the nullsafe operator is available from PHP8, but the test is using PHP7.4

sergey.semchuk’s picture

Updated the patch to fix the issue in Drupal 10 because `getSession()` method started throwing `BadMethodCallException('Session has not been set.')` and it's recommended to use `hasSession()` method.

admirlju made their first commit to this issue’s fork.

admirlju’s picture

Created a merge request to use GitlabCI testing. Also changed that null safe operator, since the module, for now, supports Drupal 9 even if it's going to be EOL in less than a month, and since it can technically run on php7.4 it's better to program with those limitations in mind.

  • japerry committed 6b1e8ae4 on 2.x
    Issue #3328196 by sergey.semchuk, admirlju: Call to a member function...
japerry’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Needs review » Fixed

rerolled with some other refactored snippets of this code and committed

  • japerry committed 6b1e8ae4 on 8.x-1.x
    Issue #3328196 by sergey.semchuk, admirlju: Call to a member function...

Status: Fixed » Closed (fixed)

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