[ZODB-Dev] transaction: synchronizer newTransaction() behavior

Siddhartha Kasivajhula CountVajhula at gmail.com
Sat Mar 9 02:54:37 UTC 2013


Hi there,
I've been discussing this issue with Laurence Rowe on the pylons-dev
mailing list, and he suggested bringing it up here.

I'm writing a MongoDB data manager for the python transaction package:
https://github.com/countvajhula/mongomorphism
I noticed that for a synchronizer, the beforeCompletion() and
afterCompletion() methods are always called once the synch has been
registered, but the newTransaction() method is only called when an explicit
call to transaction.begin() is made. Since it's possible for transactions
to be started without this explicit call, I was wondering if there was a
good reason why these two cases (explicitly vs implicitly begun
transactions) would be treated differently. That is, should the following
two cases not be equivalent, and therefore should the newTransaction()
method be called in both cases:

(1)
t = transaction.get()
t.join(my_dm)
..some changes to the data..
transaction.commit()

and:

(2)
transaction.begin()
t = transaction.get()
t.join(my_dm)
..some changes to the data..
transaction.commit()

In my mongo dm implementation, I am using the synchronizer to do some
initialization before each transaction gets underway, and am currently
requiring explicit calls to transaction.begin() at the start of each
transaction. Unfortunately, it appears that other third party libraries
using the transaction library may not be calling begin() explicitly, and in
particular my data manager doesn't work when used with pyramid_tm.

Another thing I noticed was that a synchronizer cannot be registered like
so:
transaction.manager.registerSynch(MySynch())
.. and can only be registered like this:
synch = MySynch()
transaction.manager.registerSynch(synch)

... which I'm told is due to MySynch() being stored in a "WeakSet" which
means it gets garbage collected. Currently this means that I'm retaining a
reference to the synch as a global that I never use. Just seems a bit
contrived so thought I'd mention that as well, in case there's anything
that can be done about that.

Any thoughts?

Thanks!
-Sid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/zodb-dev/attachments/20130308/fc03cf93/attachment-0001.html>


More information about the ZODB-Dev mailing list