<div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Nope. This is a bug.</blockquote>
</div><div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Really, ``begin` and ``abort`` are equivalent. It might be better if<br>
there wasn't a ``begin`` method, as it's missleading. One should be an<br>alias for the other. I'd be for deprecating ``begin``. The call to<br>``_new_transaction`` should be moved to the point in ``get`` where a<br>
new transaction is created, and ``begin`` should be made an alias for<br>``abort``.</blockquote></div><div><br></div><div><br></div>Makes sense. I've created a bug report on launchpad here:<div><br></div><div><a href="https://bugs.launchpad.net/zodb/+bug/1153116" target="_blank">https://bugs.launchpad.net/zodb/+bug/1153116</a></div>
<div><br></div><div>Let me know if that's good or if there's somewhere else I'd need to report it. Any idea when there would be a fix?</div><div><br></div><div><br></div><div><div><br><div class="gmail_quote">
On Sat, Mar 9, 2013 at 5:50 AM, Jim Fulton <span dir="ltr"><<a href="mailto:jim@zope.com" target="_blank">jim@zope.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Fri, Mar 8, 2013 at 9:54 PM, Siddhartha Kasivajhula<br>
<<a href="mailto:CountVajhula@gmail.com" target="_blank">CountVajhula@gmail.com</a>> wrote:<br>
> Hi there,<br>
> I've been discussing this issue with Laurence Rowe on the pylons-dev mailing<br>
> list, and he suggested bringing it up here.<br>
><br>
> I'm writing a MongoDB data manager for the python transaction package:<br>
> <a href="https://github.com/countvajhula/mongomorphism" target="_blank">https://github.com/countvajhula/mongomorphism</a><br>
> I noticed that for a synchronizer, the beforeCompletion() and<br>
> afterCompletion() methods are always called once the synch has been<br>
> registered, but the newTransaction() method is only called when an explicit<br>
> call to transaction.begin() is made. Since it's possible for transactions to<br>
> be started without this explicit call, I was wondering if there was a good<br>
> reason why these two cases (explicitly vs implicitly begun transactions)<br>
> would be treated differently.<br>
<br>
</div>Nope. This is a bug.<br>
<div><br>
> That is, should the following two cases not be<br>
> equivalent, and therefore should the newTransaction() method be called in<br>
> both cases:<br>
><br>
> (1)<br>
> t = transaction.get()<br>
> t.join(my_dm)<br>
> ..some changes to the data..<br>
> transaction.commit()<br>
><br>
> and:<br>
><br>
> (2)<br>
> transaction.begin()<br>
> t = transaction.get()<br>
> t.join(my_dm)<br>
> ..some changes to the data..<br>
> transaction.commit()<br>
<br>
</div>Only if (1) was was preceded by an ``abort``. The definition of<br>
``get`` is to get the current transaction, creating one, if necessary.<br>
<br>
Really, ``begin` and ``abort`` are equivalent. It might be better if<br>
there wasn't a ``begin`` method, as it's missleading. One should be an<br>
alias for the other. I'd be for deprecating ``begin``. The call to<br>
``_new_transaction`` should be moved to the point in ``get`` where a<br>
new transaction is created, and ``begin`` should be made an alias for<br>
``abort``.<br>
<div><br>
<br>
> In my mongo dm implementation, I am using the synchronizer to do some<br>
> initialization before each transaction gets underway, and am currently<br>
> requiring explicit calls to transaction.begin() at the start of each<br>
> transaction. Unfortunately, it appears that other third party libraries<br>
> using the transaction library may not be calling begin() explicitly, and in<br>
> particular my data manager doesn't work when used with pyramid_tm.<br>
><br>
> Another thing I noticed was that a synchronizer cannot be registered like<br>
> so:<br>
> transaction.manager.registerSynch(MySynch())<br>
> .. and can only be registered like this:<br>
> synch = MySynch()<br>
> transaction.manager.registerSynch(synch)<br>
><br>
> ... which I'm told is due to MySynch() being stored in a "WeakSet" which<br>
> means it gets garbage collected. Currently this means that I'm retaining a<br>
> reference to the synch as a global that I never use. Just seems a bit<br>
> contrived so thought I'd mention that as well, in case there's anything that<br>
> can be done about that.<br>
<br>
</div>This is to prevent memory leaks. Normally, the synchronizier is<br>
associated with a database. For example, the synchronizers are<br>
database connection methods. A stand-alone synchronizer seems weird<br>
to me.<br>
<br>
Jim<br>
<br>
--<br>
Jim Fulton<br>
<a href="http://www.linkedin.com/in/jimfulton" target="_blank">http://www.linkedin.com/in/jimfulton</a><br>
Jerky is better than bacon! <a href="http://zo.pe/Kqm" target="_blank">http://zo.pe/Kqm</a><br>
</blockquote></div><br></div></div>