Hi Silviu,

The old pattern is not broken if you don't change anything. However it
assumes 1 request = 1 dbsession = 1 thread pattern which is conceptually
not correct. Occurences where this may fail include

* Multiple dbsessions (e.g. one read-only for faster dbsession access)

* Async io web servers

* Celery task queues that run multiple tasks under a same worker thread

* Unit testing: multiple tests under the same thread

Thread locals are not very welcome pattern by many senior developers.
Overusing it results to harder to maintain, harder to test, code. It is
adviced to explicitly pass dbsession around when needed, or encapsulating
your code to classes that take the current dbsession as a constructor
argument.

Cheers,
Mikko

On 2 December 2016 at 02:58, Silviu Dicu <[email protected]> wrote:

> For older versions of pyramid the setup for sqlalchemy session was done
> with scooped_session similar to this
>
> DBSession = scoped_session(
>     sessionmaker(
>         autoflush=True,
>         expire_on_commit=False,
>         extension=zope.sqlalchemy.ZopeTransactionExtension()
>     )
>
> However I see that newer tutorials as well the pyramid docs
> <http://docs.pylonsproject.org/projects/pyramid/en/latest/tutorials/wiki2/basiclayout.html#content-models-with-the-models-package>
>  'promotes'
> sqlalchemy with no threadlocals where the DBSession is attached to the
> request object.
>
> Is the 'old' way broken and what is the advantage of the no threadlocals ?
> thanks!
>
> ps: posted as well http://stackoverflow.com/questions/40922933/pyramid-
> with-sqlalchemy
>
> --
> 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/4413dd47-971b-41af-9fda-f82574c2d62f%
> 40googlegroups.com
> <https://groups.google.com/d/msgid/pylons-discuss/4413dd47-971b-41af-9fda-f82574c2d62f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Mikko Ohtamaa
http://opensourcehacker.com
http://twitter.com/moo9000

-- 
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/CAK8RCUsrYihM%3Dpcp8jgigO4buigdH3kgN%2BXUdUO21nRVbrGrhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to