home contents changes options help subscribe edit (external edit)

In Zope every request you make from a web browser becomes one transaction. This transaction will either fully succeed, or fully fail. If it fails, no changes will be saved (that is the whole point of transactions, after all).

For the most part you as a developer do not have to care about this. It is all automatic. But sometimes you do need to care about it.

Controlling transactions

Sometimes you need to control the transaction, for example if you need to create sub-transactions to save data to the ZODB before going on to the next step of the process, or if you need to abort the current transaction without raising an error. (No, i don't know why you might want to do that, but you can.)

You can get hold of the current transaction with the get_transaction() call. This has the necessary methods to create subtransactions, or abort the transaction with get_transaction().abort().

Here some more detailed information would be nice, as I haven't done this much.

Hooking into the transaction

Another case where you need to use the transaction mechanism, is if you store data outside of the ZODB, for example in an SQL database, or on disk. Doing this IS rather complicated, but thankfully other people have already done all the work for you. All you need is to subclass the VTM class from the TM.py file, and supply your own _finish() and _abort() methods. See ExtFile for an example of how to use it this (that is also where I found the file).

There are some things to think about: For example, you can not change the objects attributes in _finish() as these probably already have been written. And of course, andy changes you do in _abort() will just be thrown away.

TM.py



subject:
  ( 34 subscribers )