TurboGears/tg2

DBSessionRemoverMiddleware only on 1st Database

Opened this issue · 2 comments

If I have multiple databases with multiple sessions, do I need a separate DBSessionRemoverMiddleware added to the app for each of the sessions?

Currently AppConfig adds DBSessionRemoverMiddleware to only one session.

` def _add_sqlalchemy_middleware(self, conf, app):
"""Set up middleware that cleans up the sqlalchemy session.

    The default behavior of TG 2 is to clean up the session on every
    request.  Only override this method if you know what you are doing!

    """
    dbsession = conf.get('SQLASession')
    if dbsession is None:
        dbsession = conf['DBSession']
    return DBSessionRemoverMiddleware(dbsession, app)`

If I should attach DBSessionRemoverMiddleware to each session, what is the best way to do this?
Should I overwrite the _add_sqlalchemy_middleware function of AppConfig?

Can you provide a link to a working example of latest 2.3.10 Turbogears configured with multiple databases?

amol- commented

Thanks for pointing this out, I'll update the documentation in development branch to include an example with DBSessionRemoverMiddleware.