Call to a member function get() on null in Drupal\autologout\EventSubscriber\AutologoutSubscriber->onRequest()

Created on 20 December 2022, almost 2 years ago
Updated 11 October 2023, about 1 year ago

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.

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
🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇧🇾Belarus sergey.semchuk

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇾Belarus sergey.semchuk

    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.

  • First commit to issue fork.
  • @admirlju opened merge request.
  • 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.

Production build 0.71.5 2024