[ZODB-Dev] ZODB-Dev Digest, Vol 108, Issue 17

Claudiu Saftoiu csaftoiu at gmail.com
Thu Apr 5 17:12:20 UTC 2012


>
> Hello retry shall be made on a transaction basis.
>
> I would say, that while for the regular_view retry may be handled by a
> middleware or such (the publisher in Zope2 ?), you may want to manage it
> in my_view around your transaction.
>
> in my_view you do transaction commit, so you won't undo the
> slow_no_conflict part if you fail in the second part (if it was not your
> intent you shall use subtransactions).
>
> So you may do something like :
>
> from ZODB.POSException import ConflictError
>
> def my_view(request):
>
>     transaction.begin()
>     slow_no_conflict()
>     transaction.commit()
>
>     do_retry = True
>     while do_retry:
>        try:
>           transaction.begin()
>           fast_yes_conflict(avar)
>           transaction.commit()
>           do_retry = False
>        except Exception, e:
>           transaction.abort()
>           do_retry = isinstance(e, ConflictError)
>
>
> Hope this helps !
>

That does help, thanks! Makes a lot of sense, too. Question - will hooks
added with `addAfterCommitHook()` be called
if a transaction is aborted? Also, in what situation is a web request
retried automatically - is it if
the function handling the request raises a ConflictError (e.g. by not
catching a .commit() that fails)?

Thanks,
- Claudiu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/zodb-dev/attachments/20120405/011a2a52/attachment.html>


More information about the ZODB-Dev mailing list