Check for session before calling getSession(), or catch SessionNotFoundException

Created on 25 June 2025, 2 days ago

Problem/Motivation

The symfony method \Symfony\Component\HttpFoundation\RequestStack::getSession throws a SessionNotFoundException when a session is not available - for example when invoked through drush.

However, callers to this method do not always handle or try to prevent the exception, and do not declare any @throws statements.

For example, \Drupal\Core\TempStore\SharedTempStoreFactory::get: if called in the context of a drush command, this method throws the exception.

Proposed resolution

Callers to getSession should do one of the following:

  • check for session existence first, do not call if there is no session
  • catch the SessionNotFoundException
  • declare @throws SessionNotFoundException

Remaining tasks

Identify and update getSession callers.

User interface changes

none

Introduced terminology

none

API changes

none (maybe)

Data model changes

none

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.2 πŸ”₯

Component

base system

Created by

πŸ‡ΊπŸ‡ΈUnited States AaronBauman Philadelphia

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024