[ZODB-Dev] ConflictError?

Jeremy Hylton jeremy@zope.com
Thu, 26 Jul 2001 16:36:10 -0400 (EDT)


>>>>> "CW" == Chris Withers <chrisw@nipltd.com> writes:

  CW> Is it okay to do something like the following:

This will work if you add an abort on error:

for x in y:

  get_transaction().begin()
  ...do stuff with x...
  try:
    get_transaction().commit()
  except ConflictError:
    get_transaction().abort() # otherwise you'll keep conflicting
    y.append(x)

But as Steve pointed out, you could get stuck repeating forever if
something goes wrong.  It would be safer to do something like:

for attempts in 1, 2, 3:
    for x in cur:
        failed = []
        try:
            ...
        except ConflictError:
            get_transaction().abort()
            failed.append(x)
    if failed:
        cur = failed
    else:
        break

Jeremy