[Zope] Undo Python Script

Tino Wildenhain tino at wildenhain.de
Fri Jan 23 07:21:42 EST 2004


Hi MArco,

Marco Mans schrieb:
> Hello Zopers!
>  
> I'm currently writing a script that adds some ExtFiles and then execute 
> an external method.
> Here's the script [Script1]:
>  
> context.data['0002']['folder1'].manage_addProduct['ExtFile'].manage_addExtFile(id='1', 
> title='file1', file=file1)
> context.data['0002']['folder1'].manage_addProduct['ExtFile'].manage_addExtFile(id='2', 
> title='file2', file=file2)
> context.data['0002']['folder1'].manage_addProduct['ExtFile'].manage_addExtFile(id='3', 
> title='file3', file=file3)
> 
> context.runExternalMethod(params) 
> return 'OK'
>  
> When the external method causes NO errors, the Extfiles are made. But 
> when the Extrenal method causes
> an error, zope shows up the standard_error_message and the ExtFiles are 
> not made.....
> I then executed the script from another script [Script2]:
>  
> try:
>   context.Script1()
> except:
>   return 'ERROR'
> else:
>   return 'OK!'
>  
> When Script1 causes an error (from the extrernal method) the extfiles 
> are made. Zope shows 'ERROR'.
> Why does this happen. When I execute Script1 from Script2 without 
> try-except the extfiles are not made
> when the script causes an error...
> What must i add to undo all actions made in Script1?
>  

ZPublisher encapsulates all actions in a request into a transaction.
If an exception occurs and bubbles up to the ZPublisher, it rolls
back the transaction and shows your defined standard_error_page in
context if available.

If you cought your exception by yourself, ZPublisher never knows
and therefore cannot rollback.
Beside hacking the transaction machinerie here, you can simply
write your own standard_error_page, look for the exception type
you expect and provide your "ERROR" message in that case, all
other exceptions can go to the copy of the default error_page.

Regards
Tino Wildenhain




More information about the Zope mailing list