Check for session before relying on session values (from SharedTempStoreFactory)

Created on 25 June 2025, 2 days ago

Given:

  • Session is not available in drush context. Calling \Symfony\Component\HttpFoundation\RequestStack::getSession will throw an unhandled exception.
  • \Drupal\Core\TempStore\SharedTempStoreFactory relies on session context to retrieve any stored values
  • \Drupal\apitools\ClientManager relies on SharedTempStoreFactory to initialize its api clients
  • \Drupal\apitools\Routing\ClientConfigForm relies on ClientManager to build routes
  • drush operations like updb and cr lead to route rebuilding, and do not initialize a session
  • This leads to a fatal error - unhandled SessionNotFoundException during common drush operations

Proposed resolution(s):
We want to rebuild routes during drush operations, so probably not a good idea to just eat the exception and skip it. And, we need the plugin definition in order to build the route.

So, the solution is to instantiate the client plugin instance by calling the constructor, but avoid calling the client plugin's init() method - where the session is invoked.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

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