bbangert / beaker

WSGI middleware for sessions and caching
https://beaker.readthedocs.org/
Other
517 stars 147 forks source link

How to set sa options through SessionMiddleware? #208

Closed stigok closed 3 years ago

stigok commented 3 years ago

I am using the SessionMiddleware with bottlepy and initialising it directly. However, I'm not sure how I should define the variables. Specifically I'm looking for how to add pre_ping kwarg to the sa.create_engine call. Currently I'm using the below configuration when constructing the SessionMiddleware, which works well with type and the url, but the echo param does not seem to echo anything, so not sure if the pre_ping works either.

session_opts = {
    "session.path": "/",
    "session.type": "ext:database",
    "session.url": app.config["app.dburi"],
    "session.key": "app.session.id",
    "session.timeout": 2592000,
    "session.httponly": True,
    "session.secure": app.config["app.cookie_secure"],
    "session.cookie_expires": 2592000,
    "session.cookie_domain": app.config["app.domain"],
    "session.domain": app.config["app.domain"],
    "session.sa_opts": dict(pre_ping=True, echo=True),
    "session.sa.echo": True,
}

beaker_app = beaker.middleware.SessionMiddleware(app, session_opts)

I guess I don't understand the naming convention of the configuration parameters.

stigok commented 3 years ago

Eventually I found a way after reading through the code.

beaker_app = beaker.middleware.SessionMiddleware(
    app, 
    session_opts,
    sa_opts={"sa.pool_pre_ping": True, "sa.echo": True},
)