[ZPT] Using on-error allows transaction to commit?

Brent Hendricks brentmh@ece.rice.edu
Thu, 13 Sep 2001 10:20:53 -0500


Here's my setup:

I have a ZPT which calls a python script.  That script writes some
things to a dabatase and then calls an external method that does a CVS
commit.  What I'd like is if the CVS commit fails, for the Zope
transaction to be aborted so the database writes from the python
script don't get committed.

This seems to work fine if my external method raises an exception on
failure.  The exception causes Zope to abort the transaction and all
is well with the world....except that I'd like to detect this error
and print a nice message to the user explaining what to do.  I figured
that tal:on-error would be a good way to do it.  The problem is that
when on-error catches the exception, Zope no longer aborts the
database transaction.

I tired catching the exception myself in the python script and
manually calling get_transaction().abort() but get_transation()
doesn't seem to be defined for python scripts.  I suppose I could try
putting that in my external method, but that just seems like the wrong
place to do it.

Any help is appreciated,
Brent

-------------------------------------------------------------------------

"The programmer, like the poet, works only slightly removed from pure
 thought-stuff.  He builds his castles in the air, from air, creating
 by exertion of the imagination.  Few media of creation are so
 flexible, so easy to polish and rework, so readily capable of
 realizing grand conceptual structures."
                        -- Frederick Brooks, Jr., The Mythical Man Month