TurboGears / tg2

Python web framework with full-stack layer implemented on top of a microframework core with support for SQL DBMS, MongoDB and Pluggable Applications
http://www.turbogears.org/
Other
805 stars 78 forks source link

DBSessionRemoverMiddleware only on 1st Database #84

Closed ghost closed 5 years ago

ghost commented 7 years ago

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 7 years ago

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

amol- commented 5 years ago

This is now documented properly: https://turbogears.readthedocs.io/en/latest/cookbook/multiple-databases.html#change-the-way-your-app-loads-the-database-engines