- marked as task
- changed milestone to 0.9.10
- changed component to documentation
Feature Request - ScopedSession.session_factory as an API method
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,
Comments (7)
-
repo owner -
reporter Wonderful!
It's implemented as a class attribute. I couldn't find any references for how that should be documented -- most similar things are class methods or properties.
The only approach I can think of is adding a line to the class and init docstings. Is there a better way?
-
repo owner sphinx is able to get class attributes (usually...with some v. frustrating failures), so if you docstring underneath that should work
-
reporter Great! Thanks. I see that form being used on some package-level variables, and know what to look for in the Sphinx docs.
-
reporter cross reference to pull request: https://bitbucket.org/zzzeek/sqlalchemy/pull-request/50/updated-docstrings-for-ormscoping
-
repo owner - changed milestone to 1.x.xx
-
repo owner - edited description
- changed status to resolved
this was merged in january 2016
- Log in to comment
it's not underscored, so it's public. I probably refer to it in some wiki recipe or blog post somewhere. Feel fee to document it.