pyramid_tm does have a configurable activate_hook that you can use to turn
off the TM for certain endpoints. You would need to coordinate that with
something else that managed the transaction. If I were doing it myself I'd
probably configure my activate hook to return true/false based on an custom
attribute on the request like `request.activate_tm`. I'd then set this to
False in a tween mounted over pyramid_tm. The reason I'd do it this way is
because if you're turning off pyramid_tm then you probably still need to do
something to manage the connection - and a tween would be a good spot to do
this.

That being said, I'd ask why you would want to turn it off instead of just
committing multiple times? You just need to use `request.tm.commit()`,
`request.tm.abort()` and `request.tm.begin()` instead of
`request.dbsession.commit()`. Make sure to always call begin after
commit/abort and things should work fine - whether it's a good idea or not
in general (see Mikko's comments) is a separate question.

- Michael

On Thu, Feb 6, 2020 at 7:03 PM Jonathan Vanasco <jonat...@findmeon.com>
wrote:

> one of my apps uses pyramid_tm, but has reached a point where one
> (possibly two) views (out of dozens) need to make explicit commits with the
> SqlAlchemy session.
>
> does anyone know if it's currently possible to handle this?  i have a few
> apps that only integrate pyramid_tm on a small subset of views, but i
> haven't tried to bypass it on a single view in many years.  I'm trying to
> avoid a secondary database connection, because this app can support a
> sqlite database and I've had problems with too many connections and sqlite
> in the past.
>
> --
> 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 pylons-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pylons-discuss/c3d3f561-8bcc-4c20-b1e8-f2aa147483f0%40googlegroups.com
> <https://groups.google.com/d/msgid/pylons-discuss/c3d3f561-8bcc-4c20-b1e8-f2aa147483f0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

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 pylons-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/CAKdhhwENeR4239BK2cNYTudNn28-uiDTkWQX%3D4GhkqgwrwNG_g%40mail.gmail.com.

Reply via email to