-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Registering new session bag does not initialize it #10707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Registering a new Bag (before) starting the session can be done using a CompilerPass. But initializing a bag automatically on registering when the session is already started should indeed be possible. /cc @Drak |
@imunhatep What you are suggesting is a code smell. Bags are initialized only when the session is started so you must instantiate your session objects as you require before hand which can be done as suggested as @sstok suggests or just by altering the initial service definitions. Remember, bags are not aware of the session so any attempt to make bags do things to the session would mean ugly dependencies which is another clear code smell. |
I agree with @imunhatep @Drak Indeed bags are not aware of the session neither they should be, but since the bag registration is invoked from @sstok This approach looks very nice :) |
Just fell into this pitfall. I used |
I just ran into this issue, too. It was really annoying, to understand that the session has to be started after the bag was added. Current, I see two options to fix this:
I'd prefer the first way. What do you think? I can provide a fix for this, if you agree. |
I think we should go with option 2. |
…ed sessions (xabbuh) This PR was merged into the 2.3 branch. Discussion ---------- [HttpFoundation] exception when registering bags for started sessions | Q | A | ------------- | --- | Branch | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10707, #16136 | License | MIT | Doc PR | Commits ------- c4a5b67 exception when registering bags for started sessions
If the session is already loaded:
Currently session handlers allow dynamically register new attribute bags, but does not initialize them on registering. And does not throw any exception that created session attribute bag is not saving any data to session.
Developer have to define custom session service and register all bags there (before session loads) or initialize bags by hands.
Symfony 2.4.2
The text was updated successfully, but these errors were encountered: