Jens, by default your example is true, but it is not true in the cookiecutter configuration. The value of request.tm is defined by the tm.manager_hook setting and by default it is the threadlocal transaction.manager. The cookiecutter overrides the hook (and I suggest you do as well) to define a non-threadlocal manager configured in explicit=True mode which will help weed out bugs accessing transactions after they have been committed. I strongly suggest any code you write that needs the tm should use request.tm, not transaction.manager - as the former is configurable.
- Michael On Sat, Sep 1, 2018 at 5:57 AM <[email protected]> wrote: > Hi, > > According to the documentation here > <https://docs.pylonsproject.org/projects/pyramid_tm/en/latest/>, “Pyramid > <https://docs.pylonsproject.org/projects/pyramid_tm/en/latest/glossary.html#term-pyramid> > requests [to] join the active transaction > <https://docs.pylonsproject.org/projects/pyramid_tm/en/latest/glossary.html#term-transaction> > as provided by the Python transaction > <https://pypi.org/project/transaction/> package”. Looking at the > transactions code, the default transaction manager used is a > ThreadTransactionManager > <https://github.com/zopefoundation/transaction/blob/501a2934a1031f4def92701a44ebca8a317dd8a6/transaction/_manager.py#L212>, > i.e. one transaction per Python execution thread. > > Now I did follow the Pyramid-SQLAlchemy-Cookiecutter > <https://github.com/Pylons/pyramid-cookiecutter-alchemy/> recipe where DB > sessions join the request’s transaction. Considering that a single incoming > request is handled in Pyramid by a single thread (correct?) is it safe to > say that the following is true? > > import transaction > > @view_config(…) > def some_view(request): > # Request's transaction manager is the thread's transaction manager. > request.tm == transaction.manager > # Request's and thread's and tm's transaction is the same object. > request.tm.get() == transaction.get() # == transaction.manager.get() > > Thanks! > Jens > > -- > 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/79da9d5a-91e9-483e-b96f-b5e54cc3f1a5%40googlegroups.com > <https://groups.google.com/d/msgid/pylons-discuss/79da9d5a-91e9-483e-b96f-b5e54cc3f1a5%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/CAKdhhwEpmYEvEjFx74MOBHA-iSM%2BC1KNtBynkxBTPM06ufvuyQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
