Skip to content

Symfony Session doesn't work if set handler_id via environment variable #45202

Closed
@linuxitux

Description

@linuxitux

Symfony version(s) affected

5.3.0/5.4.5

Description

Symfony throws Unsupported Connection: "session.handler.native_file" if you set handler_id in config/packages/framework.yaml to session.handler.native_file via .env variable.

I want to have the ability to switch between different session handlers in my application, so I added a .env variable named "SESSION_HANDLER" to set handler_id in framework.yaml. I want to support several session handlers, including native_file.

If I set a Redis URL in my SESSION_HANDLER .env var, it works perfectly and uses my Redis node as the session handler. But, if I set SESSION_HANDLER to session.handler.native_file, I got:

InvalidArgumentException

Unsupported Connection: "session.handler.native_file".

In vendor/symfony/http-foundation/Session/Storage/Handler/SessionHandlerFactory.php  (line 85) .

How to reproduce

Add SESSION_HANDLER var in .env and set it to session.handler.native_file:

.env:

SESSION_HANDLER=session.handler.native_file

Set handler_id via .env var in framework.yaml:

config/packages/framework.yaml:

framework:
    session:
        handler_id: '%env(SESSION_HANDLER)%'

internal_server_error.txt

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions