Even if the session object is the same (which it is) I believe
transactional state has been properly cleaned up by zope.sqlalchemy
invoking rollback/commit/close on the session itself. However the session
and any strong refs it's storing may never be released. As far as I know
this shouldn't actually cause a problem but it is a smell for sure.
If you're stuck with the global session (of course I recommend switching),
you may just want to add a tween OVER pyramid_tm that invokes
DBSession.remove(). This can be done very simply. For example:
def tm_cleanup_tween_factory(registry, handler):
def tween(request):
try:
return handler(request)
finally:
DBSession.remove()
return tween
def includeme(config):
config.add_tween(__name__ + '.tm_cleanup_tween_factory',
over='pyramid_tm.tm_tween_factory')
Then in your app just config.include('dotted.path.to.this.module') next to
your config.include('pyramid_tm') logic.
On Thu, Jun 22, 2017 at 12:06 PM, Jonathan Vanasco <[email protected]>
wrote:
> 1. You probably shouldn't use a global sqlalchemy session like that. It
> is the cause of many developer's problems. There should probably be a
> ticket to remove/update that howto, so it references the current
> cookiecutter -- which stashes the session onto the request.
>
> 2. pyramid_tm doesn't close/remove the session when finished. if you look
> at the code, it doesn't touch sqlalchemy at all. it just integrates
> zope.transaction's hooks with pyramid. the sqlalchemy hookup is handled by
> passing in the zope_sqlalchemy's extension -- which handles all the hooks
> if sqlalchemy is used. That package is using `session.close()` not
> `session.remove()`, because 'remove' is specific to scoped sessions (and
> the package supports regular sessions as well) .
>
> tldr; pyramid_tm is a bad place to handle this sort of thing, because
> there are multiple database backends (sqlalchemy, zope) and multiple
> session types (scoped, explicit).
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/pylons-discuss/6fba4f55-824e-4a31-ae63-409caaa8563a%
> 40googlegroups.com
> <https://groups.google.com/d/msgid/pylons-discuss/6fba4f55-824e-4a31-ae63-409caaa8563a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/CAKdhhwFtK49RVUzgmVvYCG8dYM6nbCm1QdpccST9SuN%3DPK1OPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.