SessionManager improperly abstracts Symfony's Session Component

Created on 5 April 2018, about 6 years ago
Updated 15 February 2024, 4 months ago

Problem/Motivation

The upgrade to Symfony 3.4 introduced the use of the SessionProxyBag for any bags within the session system. (Found in this commit, Thanks to Tim Plunkett): https://github.com/symfony/http-foundation/commit/d9625c8abb907e0ca2d750...

Our usage of the SessionManager often results in code like this:


$this->sessionManager->getBag('attributes')->set('foo', 'bar');

This would have been fine and worked in 8.4.x and earlier, but in 8.5 you must now:


$this->sessionManager->getBag('attributes')->getBag()->set('foo', 'bar');

This is because getBag('attributes') used to return an AttributesBag and now returns a SessionProxyBag which wraps the AttributesBag. This is super confusing for a number of reasons, but most importantly, our session handling appears to be a strange "Drupalism" of an abstraction around most of the components Symfony provides without directly using the paradigm they expect. I've not dug in enough to know all the nuance on this, but this was definitely an API break for us because of HOW we use it. Also, worth pointing out that the expected return values make both sets of code above completely unsafe without a ton of additional type checking.

Proposed resolution

We might want to look at how we handle sessions in general and come up with a longer term solution, but for the foreseeable future, we should probably change the getBag() implementation on SessionManager today to identify when we're dealing with a SessionProxyBag and return the bag it's wrapping. This would have completely prevented me from running into this problem. (Again, thanks to Tim for the suggested fix there).

Remaining tasks

Determine appropriate course of action.

User interface changes

None

API changes

This would actually return the API to what it was in 8.4.x, so I consider the current state an api break.

Data model changes

N/A

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
Request processingΒ  β†’

Last updated about 10 hours ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States EclipseGc

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.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Is this still an issue?

    ::getBag is not implemented in SessionManager so falls back to sf's NativeSessionStorage

Production build 0.69.0 2024