[ZODB-Dev] RFC: Pre-commit hooks
Jim Fulton
jim at zope.com
Mon Apr 4 10:53:05 EDT 2005
I propose to add a pre-commit hook to ZODB.
Problem
Sometimes, applications want to execute some code when
a transaction is committed. For example, one might want to
delay object indexing until a transaction commits, rather
than indexing every time an object is changed. Or, someone
might want to check invariants only after a set of operations.
Proposal
We add a new method to transaction objects:
def beforeCommitHook(hook, *args, **kw):
"""Register a hook to call before the transaction is committed
The provided hook will be called after the transaction's
commit method has been called, but before the commit process
has been started. The hook will be passed the given
positional and keyword arguments.
Multiple hooks can be registered and will be called in order.
This method can be called from executing hooks. That is, executing
hooks can register more hooks. (Applications should take care
to avoid creating infinite loops by recursvely registering hooks.)
Hooks are not called and are discarded if the transaction aborts.
"""
We would also modify transaction commit methods to call hooks. Hooks would
not be called on sub-transaction commit. (If necessary, we could add
separate sub-transaction hooks, but I don't think we need this.)
This hook is very simple to use an implement and, I think, addresses
the requitement much more directly than implementing special data
managers.
Thoughts?
Anyone up for implementing this (with a doctest, of course)?
I'd like to get this into ZODB 3.4.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the ZODB-Dev
mailing list