Jonathan gives a pretty good description of how the packages fit together.
He left one out, however, which I'll mention.
https://docs.pylonsproject.org/projects/pyramid-retry/en/latest/
pyramid_retry wraps pyramid_tm and looks for failed transactions that
failed due to some serialization/locking issue (or any other custom
retryable exception in your app). You can configure pyramid_retry to retry
a request before bubbling the error to the client. This can handle some
basic locking issues or serialization exceptions based on the isolation
levels you choose in your underlying database connection.
A final tidbit is that most of this advice is focused on connections bound
to pyramid_tm such as those in the cookiecutter. For example
``request.dbsession`` is always bound to the transaction managed by ``
request.tm``. Let's call this the request's primary transaction - the
transaction used for all normal operations during the request. It is good
to think about it as begun and committed/aborted out of your control when
the request begins/ends. There are other use cases where you want to commit
work partway through a request... you can do this yourself by making
database sessions that are not joined to ``request.tm``. For example in the
cookiecutter you can make your own sessions via ``mysession =
request.registry['dbsession_factory']()``. You can then commit/abort this
transaction yourself in a different lifecycle.
- Michael
On Mon, Nov 27, 2017 at 2:25 PM, Jonathan Vanasco <[email protected]>
wrote:
> The sqlalchemy cookie cutter uses pyramid_tm to handle the transaction.
> The docs on that package should answer all your questions:
>
> https://docs.pylonsproject.org/projects/pyramid_tm/en/latest/
>
> Basically what happens is this:
>
> * the actual transaction management is provided by zope's transaction
> package (http://zodb.readthedocs.io/en/latest/transactions.html)
> * the glue between zope and sqlalchemy is zope.sqlalchemy (
> https://pypi.python.org/pypi/zope.sqlalchemy)
> * the template uses pyramid_tm to register a transaction around the
> request using a pyramid tween.
> * pyramid_tm manages a "meta transaction" that has different components:
> one of which is the database "transaction", but there might also be joined
> transactions for mailing, celery, and other tasks.
>
> When the database transaction fails, an exception is raised. You can
> write a view to catch that exception, as explained in the pyramid_tm docs.
>
> In your example, two things can happen based on the The order of access in
> the race condition and your DB's configuration.
>
> 1. One transaction succeeds, the other fails.
> 2. Both fail (deadlocks or other db errors).
>
> SqlAlchemy should trap almost any driver error regarding this, and
> abstract it into one of it's own core exceptions (
> http://docs.sqlalchemy.org/en/latest/core/exceptions.html).
>
> When one of the joined transactions fails, the transaction manager
> notifies the rest to issue a rollback-- so the database should rollback,
> email queues are removed, etc.
>
> --
> 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/012c9079-61ed-4462-8d4f-a0a1b8ae4e33%
> 40googlegroups.com
> <https://groups.google.com/d/msgid/pylons-discuss/012c9079-61ed-4462-8d4f-a0a1b8ae4e33%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/CAKdhhwG-frSF3QgK6hPaX5juX2B67rsfEyKqRdXKJEnBs-M6hg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.