[Zope-dev] Re: post publishing hook

Dieter Maurer dieter at handshake.de
Sun Apr 3 13:41:16 EDT 2005


Christian Heimes wrote at 2005-4-1 22:28 +0200:
> ...
>You want to bind some actions to the transaction system because you want 
>to execute some code at the end of the first phase of the 2 phase 
>commit.

I do not think that Florent wants to execute things at the end
or in the first commit phase. Instead, he wants to execute something
*BEFORE* this phase.

>Hooking into the transaction machinery of ZODB is very easy. Write 
>your own DateManager implementing the IDateManager interface and 
>register it into the current transaction using get_transaction.register(DM).
>
>For your use case overwrite the tpc_vote() method of the data manager to 
>do the indexing at the boundary between the two phases.

This will not work for Florent's use case,
at least not in the current ZODB (for Zope 2.7).

Reason:

  The transaction freezes the set of objects it processes
  in the commit *BEFORE* the first commit phase.

  Therefore, no "tpc_vote" is allowed to modify any persistent
  object. Failure to do so leads to extremely nasty
  persistency errors (the object is marked changed but
  no transaction knows about it -- no change to this object in the future
  will get persisted until a restart).

>Jens Vagenpohl's mail host and Chris McD's blob have example code for you.

But they do not change persistent objects (at least, I hope so).

-- 
Dieter


More information about the Zope-Dev mailing list