Retryable Exception on commit does not cause retries #4

Closed
jamadden opened this Issue Apr 19, 2012 · 1 comment

Comments

Projects
None yet
1 participant

In 0.4, the pyramid_tm.Attempt class is used as a context manager. If no exception occurs in the with statement, then Attempt.__exit__ commits the transaction. If committing the transaction then raises an exception, Attempt.__exit__ returns a boolean value with the intent of allowing the loop in tm_tween to retry.

However, according to the Python language documentation for with:

If the suite was exited for any reason other than an exception, the return value from exit() is ignored,
and execution proceeds at the normal location for the kind of exit that was taken.

Therefore, if committing raises an exception, this return value is ignored. The body of the loop executes a return statement, so the "normal location" is going to return the response and the loop is never going to be retried, and conflict errors that occur during a commit are going to be effectively silently swallowed.

In our code, our workaround was to manually call transaction.commit() in a tween inserted just under pyramid_tm. This ensures that an exception will be raised and passed to Attempt.__exit__, so the return value (whether to retry) is not ignored by the interpreter.

jamadden commented Jan 6, 2013

The imperative approach in 0.7 should resolve this issue.

@jamadden jamadden closed this Jan 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment