[ZODB-Dev] preventing a transaction from committing within appcode
Tim Peters
tim at zope.com
Wed Sep 8 15:02:16 EDT 2004
[Jeremy Hylton]
>> The ZODB 3.3 transaction API should allow you to plugin a transaction
>> manager that implements this policy. (At least I hope it does.)
[Chris McDonough]
> That's nice though not immediately helpful for Zope 2.7.X as it still
> uses ZODB 3.2. Zope 2.8, which is supposed to ship with some version of
> ZODB 3.3, is still a long way off too, AFAICT. Darn. Do you have any
> recommendations for how to implement this in ZODB 3.2?4
Well, there isn't an explicit "transaction manager" concept in 3.2; the
default policy is implemented via the stuff rammed into __builtin__, and
another policy implemented via Connection.setLocalTransaction(). I suppose
you could replace __builtin__.get_transaction after ZODB.Transaction.py
creates it. The implementation of get_transaction() in Transaction.py
always returns a Transaction object, and cannot be tricked into refusing to
do so:
def get_transaction(_id=thread.get_ident, _t=_t, get=_t.get):
id = _id()
t = get(id, None)
if t is None:
_t[id] = t = Transaction(id)
return t
Perhaps ugly-enough code could reach into Transaction._t and replace
_t[thread.get_ident()], upon an abort(), with an instance of a new
Transaction subclass whose commit() method refused to do anything.
It may be messy no matter how you cut it.
More information about the ZODB-Dev
mailing list