[Zope3-Users] Re: Updating just a single object

Philipp von Weitershausen philipp at weitershausen.de
Wed Jun 28 13:38:03 EDT 2006


Frank Burkhardt wrote:
> Hi,
> 
> when I raise an exception in a view, no changes done to the any object
> are saved to zodb.
> 
> I would like to change that for a single object:
> 
> class MyView(BrowserView):
>    def __call__(self):
>       [...]
>       if some_test:
           transaction.abort()
>          save_object(self.context)
           transaction.commit()
>          raise MyException()
>       [...]
> 
> No other object should be saved - just self.context. How could I do that?

You can do this by explicitly rolling back the current transaction,
modifying that single object and committing the transaction so that just
those changes will be saved. Then you raise the exception and let Zope
do its things (which, among others, include rolling back the now pretty
much empty transaction).

HTH

Philipp



More information about the Zope3-users mailing list