[Zope-dev] transaction.doom() and ZPublisher
Brian Sutherland
brian at vanguardistas.net
Thu Jul 10 11:09:36 EDT 2008
On Thu, Jul 10, 2008 at 12:12:06AM -0400, Paul Winkler wrote:
> Hi,
>
> I noticed that Zope 2.11 includes a recent version of the transaction
> module including the transaction.doom() method. But I don't see any
> check for it in ZPublisher.
>
> So, if any code calls transaction.doom(), the publisher will raise a
> user-visible exception when it tries to call commit(). This seems
> less than useful :-)
>
> In the discussion I've seen of this method, eg.
> https://bugs.launchpad.net/zope3/+bug/98382 and
> http://markmail.org/message/3yshpmltvhevnrff it sounds like other
> people share my expectation... namely, that the developer should not
> have to do anything special after calling transaction.doom(); the
> transaction is not committed, and the user won't see an exception.
Yes.
>
> Is that the concensus? If so, there's an easy solution -
> apply something like the attached patch.
>
> Anybody disagree?
I havn't investigated properly, but it may be necessary to do the
isDoomed() check at a higher level where you can abort. Code running
after the commit() expects a new transaction and now will not get that.
Other than that, an explicit abort() if the transaction is doomed may be
sufficient.
Zope3 does:
def afterCall(self, request, ob):
txn = transaction.get()
if txn.isDoomed():
txn.abort()
else:
self.annotateTransaction(txn, request, ob)
txn.commit()
>
>
> --
>
> Paul Winkler
> http://www.slinkp.com
> --- Zope2/App/startup.py~ 2008-06-14 02:50:23.000000000 -0400
> +++ Zope2/App/startup.py 2008-07-10 00:08:02.000000000 -0400
> @@ -267,7 +267,8 @@
> transaction.begin()
>
> def commit(self):
> - transaction.commit()
> + if not transaction.isDoomed():
> + transaction.commit()
>
> def abort(self):
> transaction.abort()
> --- ZPublisher/Publish.py~ 2008-06-14 02:50:48.000000000 -0400
> +++ ZPublisher/Publish.py 2008-07-10 00:08:08.000000000 -0400
> @@ -314,7 +314,8 @@
> def begin(self):
> transaction.begin()
> def commit(self):
> - transaction.commit()
> + if not transaction.get().isDoomed():
> + transaction.commit()
> def abort(self):
> transaction.abort()
> def recordMetaData(self, object, request):
> --- ZPublisher/WSGIPublisher.py~ 2008-06-14 02:50:48.000000000 -0400
> +++ ZPublisher/WSGIPublisher.py 2008-07-09 23:59:57.000000000 -0400
> @@ -401,7 +401,8 @@
> def begin(self):
> transaction.begin()
> def commit(self):
> - transaction.commit()
> + if not transaction.get().isDoomed():
> + transaction.commit()
> def abort(self):
> transaction.abort()
> def recordMetaData(self, object, request):
> _______________________________________________
> Zope-Dev maillist - Zope-Dev at zope.org
> http://mail.zope.org/mailman/listinfo/zope-dev
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope )
--
Brian Sutherland
More information about the Zope-Dev
mailing list