I'm requesting that ScopedSession.session_factory become a public API method.
This is currently implemented, but hidden and undocumented.
Rationale / use-case:
We have a transaction-safe PostgreSQL application. There exists some tasks that require a separate database connection to operate independent of the transaction (generally things like logging various bits of information, such as AmazonS3 Activity, Failures due to Ratelimits, some error logging).
This is often handled with a separate database setup, but that was a bit painful to handle in a situation... and after a bit of poking around on the internals, it seems that this works:
dbSessionAlternate = dbSession.session_factory() dbSessionAutocommit = dbSession.session_factory(autocommit = True)
Originally I hoped that this would work, but they don't:
dbSessionA = dbSession() dbSessionB = dbSession(autocommit = True)
dbSessionA creates a new Session, but it's underlying connection is local to the scope/thead ( ie, dbSession.connection() == dbSessionA.connection() )
dbSessionB raises an error because it is trying to duplicate the 'scoped_session', not just the underlying session,