PostgreSQL and SQL define Serializable transaction isolation level . If you isolate transactions at this level, conflicting concurrent transactions are aborted and need to be retried.
I am familiar with the concept of transaction attempts from the Plone / Zope world, where the entire HTTP request can be played in case of transaction conflict. How can similar functionality be achieved with SQLAlchemy (and possibly with zope.sqlalchemy )? I tried to read the documentation of zope.sqlalchemy and the Zope transaction manager , but this is not obvious.
Specifically, I want something like this:
# Try to do the stuff, if it fails because of transaction conflict do again until retry count is exceeded with transaction.manager(retries=3): do_stuff()
source share