The biggest problem with pyramid_tm I've run into is wanting to rollback or commit the accumulated changes within the view without messing up the global transaction outside the view. Normally when you commit SQLAlchemy starts a new transaction afterward, but with pyramid_tm you have to use 'transaction.commit' and that messes up its transaction for the rest of request processing. Likewise if you start to do some things and then can't (because a non-transactional resource like a file can't be written or deleted), you want to roll back what you did but without messing up the entire request. Again you have to use 'transaction.abort()' or 'transaction.doom()', but that ultimately causes a 500 error which you don't want. (Then there's the case of logging, but I use separate autocommit connections outside the transaction for that so they succeed even if the request has an exception.)
Do the 'pyramid_tm' revisions offer any help with these cases? On Thu, Mar 2, 2017 at 11:29 PM, Michael Merickel <[email protected]> wrote: > Hey folks, I want to warn the community about an upcoming change to > pyramid_tm that has been a long time in the making. I'm excited about it - > but I also don't want to blindside anyone with a large-ish backward > incompatible change. > > TLDR - You may want to pin 'pyramid_tm < 2.0' until you have a chance to > understand the changes. > > There have been 3 major issues with pyramid_tm since its inception: > > 1) pyramid_tm doesn't cover exception view code so anything you do in an > exception view should not be touching transactional objects or performing > create / update / delete (non-readonly) queries. > > 2) Retry support has never fully torn down the request so if you're storing > any transactional data in a request property (like request.user) and you > have tm.attempts > 1, you may be leaking objects across transactions leading > to subtle issues. > > 3) There is lots of room for subtle bugs when you perform changes to a > transaction outside of the scope of pyramid_tm (it only covers part of the > request lifecycle). > > The resolution of these issues has involved several steps including a new > library, a new concept in pyramid and changes to the transaction library and > pyramid_tm. > > 1) The pyramid_tm tween was moved in the tween hierarchy to be OVER the > EXCVIEW tween meaning transactions are kept alive during exception views and > aborted later. > > 2) The retry support in pyramid_tm was removed and a new library was created > called pyramid_retry. This library only works with pyramid 1.9 which is > unreleased. The new retry library can will create a new request object for > every attempt, throwing away any transactional state stored on it, leading > to cleaner retries. > > 3) The transaction package now supports explicit transaction managers which > will error when they are used after a commit/abort. You should use one by > defining a "tm.manager_hook" that returns > "transaction.TransactionManager(explicit=True)". > > I hope this was helpful. We are still reviewing the changes to pyramid_tm > and 2.0 does not have a release date but let's say that I promise it won't > happen before March 15. Once that goes live you won't have any retry > support, if you're relying on it (but I doubt you are because of the issues > above) until pyramid 1.9 which also does not have a release date. :-) > > Thanks! > > - Michael > > -- > 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/CAKdhhwEngaXn-%3DQZe13oKgw81_XRUJn-AN_3S_NPOipNgxsG-w%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- Mike Orr <[email protected]> -- 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/CAH9f%3DupDsaHNC5kjxU5RGmkEt0h6qckFVm7EmvPdyEa6Ruu%2Buw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
