diff --git a/UPGRADE-5.1.md b/UPGRADE-5.1.md
index fd789861a8..eb670c66fc 100644
--- a/UPGRADE-5.1.md
+++ b/UPGRADE-5.1.md
@@ -37,6 +37,7 @@ FrameworkBundle
* Deprecated passing a `RouteCollectionBuilder` to `MicroKernelTrait::configureRoutes()`, type-hint `RoutingConfigurator` instead
* Deprecated *not* setting the "framework.router.utf8" configuration option as it will default to `true` in Symfony 6.0
+ * Deprecated `session.attribute_bag` service and `session.flash_bag` service.
HttpFoundation
--------------
diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md
index 19fd5f4c15..570d4d10a5 100644
--- a/UPGRADE-6.0.md
+++ b/UPGRADE-6.0.md
@@ -35,6 +35,7 @@ FrameworkBundle
* `MicroKernelTrait::configureRoutes()` is now always called with a `RoutingConfigurator`
* The "framework.router.utf8" configuration option defaults to `true`
+ * Removed `session.attribute_bag` service and `session.flash_bag` service.
HttpFoundation
--------------
diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
index ea7ffe7e77..6997abde9e 100644
--- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
@@ -17,6 +17,7 @@ CHANGELOG
* Added `debug:container --deprecations` option to see compile-time deprecations.
* Made `BrowserKitAssertionsTrait` report the original error message in case of a failure
* Added ability for `config:dump-reference` and `debug:config` to dump and debug kernel container extension configuration.
+ * Deprecated `session.attribute_bag` service and `session.flash_bag` service.
5.0.0
-----
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
index c2f621fe51..1f08c0ff47 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
@@ -43,11 +43,13 @@
+ The "%service_id%" service is deprecated, use "$session->getFlashBag()" instead.
+ The "%service_id%" service is deprecated, use "$session->getAttributeBag()" instead.
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php
index 530492ab8b..253947d02f 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php
@@ -11,8 +11,12 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
+use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
+
class SessionTest extends AbstractWebTestCase
{
+ use ExpectDeprecationTrait;
+
/**
* Tests session attributes persist.
*
@@ -72,10 +76,13 @@ class SessionTest extends AbstractWebTestCase
/**
* Tests flash messages work when flashbag service is injected to the constructor.
*
+ * @group legacy
* @dataProvider getConfigs
*/
public function testFlashOnInjectedFlashbag($config, $insulate)
{
+ $this->expectDeprecation('Since symfony/framework-bundle 5.1: The "session.flash_bag" service is deprecated, use "$session->getFlashBag()" instead.');
+
$client = $this->createClient(['test_case' => 'Session', 'root_config' => $config]);
if ($insulate) {
$client->insulate();