Problem/Motivation

We need to address some deprecated code that throws a SessionNotFoundException in Drupal 10 (as the result of updating Symfony).

Here's the deprecation:
Calling "Symfony\Component\HttpFoundation\Request::getSession()" when no session has been set is deprecated since Symfony 4.1 and will throw an exception in 5.0. Use "hasSession()" instead.

While updating the Features Permissions module for Drupal 10, I ran into this:

1) Drupal\Tests\features_permissions\Kernel\FeaturesCrudTest::testFeatureRevert
Symfony\Component\HttpFoundation\Exception\SessionNotFoundException: Session has not been set.

/var/www/html/vendor/symfony/http-foundation/Request.php:708
/var/www/html/web/modules/contrib/features/src/FeaturesAssigner.php:432
/var/www/html/web/modules/contrib/features/src/FeaturesAssigner.php:399
/var/www/html/web/modules/contrib/features/modules/features_ui/src/Form/FeaturesDiffForm.php:106
/var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php:534
/var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php:281
/var/www/html/web/modules/contrib/features_permissions/tests/src/Kernel/FeaturesCrudTest.php:49
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

Steps to reproduce

Features doesn't seem to have test coverage that catches this - at least when I run 5.0.x tests locally.
So.. run D10 tests at https://www.drupal.org/project/features_permissions/issues/3324858

Proposed resolution

Call Request::hasSession() before Request::getSession().

Remaining tasks

Open MR
Review
Commit

User interface changes

None

API changes

None

Data model changes

None

Issue fork features-3324881

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Chris Burge created an issue. See original summary.

Chris Burge’s picture

Test failures appear unrelated to this MR. Development is blocked by #3324885: 5.0.x Branch Tests Failing.

Chris Burge’s picture

The MR also uses dependency injection for the request_stack service in Features' features_assigner service.

  • nedjo committed 25e3358b on 5.0.x authored by Chris Burge
    Issue #3324881: Check for session before calling Request::getSession()
    
Chris Burge’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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