transaction.doom() for form processing
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 3 |
Fix Released
|
Medium
|
Unassigned |
Bug Description
I think there's a problem with the use of transaction.abort() in the EditView and similar code.
class EditView(
...
def update(self):
...
if Update in self.request:
try:
# We should not generate events when an adapter is used.
# That's the adapter's job.
if changed and self.context is self.adapted:
except WidgetsError, errors:
else:
...
The transaction is aborted when there is a widget error. The problem with doing this is that a new transaction will implicitly begin. (That's a misdesign in the transactions system in my opinion, but a separate issue.) At the end of the request processing, the publisher will see that no exception bubbled up, and the (new) transaction has no conflicts or whatever, and will commit the transaction. So, if any processing is done after the transaction.abort() in the code above, that causes actions or writes on a commit, these actions or writes will occur, even though this is not what is intended for the application.
I think the intention behind the form-processing code is to Doom the transaction. That is, to ensure that the transaction will not be committed at any future time, but to allow the transaction to proceed with its present state.
I proposed a transaction.doom() API a while ago.
http://
The changes would be:
* Add transaction.doom() to the API.
* Calling transaction.
* The publication code catches this exception from its call to commit(), and handles it by aborting the transaction.
* Fix the bug in EditView and FormView by changing abort() to doom(). (Also, check if there are other places inappropriately using transaction.
* Document that code running inside a Zope request should never use transaction.
* Optionally: extend the transaction API to allow you to ask "is this transaction doomed?"
I think EJB has this API:
EJBContext. setRollbackOnly ();
Maybe they were worried about the religious connotations of "Doom".