Hi, there were some problems with the code snippets in the book. I updated them here:
http://zodb.readthedocs.org/en/latest/transactions.html#before-commit-hooks For some reason I could only get synch to work using classmethod. Carlos de la Guardia On Sat, Feb 16, 2013 at 3:56 AM, Siddhartha Kasivajhula <countvajh...@gmail.com> wrote: > Hi there, > I'm not able to get before/after commit hooks or synchronizers to work, hope > someone here can explain what I'm doing wrong (or please point me at the > relevant list). I'm following the tutorial here: > > http://www.zodb.org/zodbbook/transactions.html > > .. and got the PickleDataManager working. But when I add the before- and > after-commit hooks verbatim from the tutorial, I get the following error: > > Traceback (most recent call last): > File "pickledm.py", line 145, in <module> > transaction.commit() > File > "/Users/siddhartha/.virtualenvs/pyramid/lib/python2.7/site-packages/transaction/_manager.py", > line 107, in commit > return self.get().commit() > File > "/Users/siddhartha/.virtualenvs/pyramid/lib/python2.7/site-packages/transaction/_transaction.py", > line 339, in commit > self._callBeforeCommitHooks() > File > "/Users/siddhartha/.virtualenvs/pyramid/lib/python2.7/site-packages/transaction/_transaction.py", > line 413, in _callBeforeCommitHooks > hook(*args, **kws) > TypeError: before_commit() got an unexpected keyword argument 'a' > > When I pass in a blank dict instead of the {'a':1} from the tutorial, I get > this error: > > File "pickledm.py", line 17, in before_commit > for arg in args: > TypeError: 'int' object is not iterable > > ... and I find that, in fact, printing 'args' inside the hook function shows > that it is equal to 1, and not the tuple (1,2) that was passed. > > I also tried adding a synchronizer, and initially got this error: > > TypeError: unbound method beforeCompletion() must be called with synch > instance as first argument (got Transaction instance instead) > > It looked like this may have been due to a typo in the tutorial, I changed: > > transaction.manager.registerSynch(sync) > > to: > > transaction.manager.registerSynch(sync()) > > ...to pass an instance instead of a class and the error goes away. > Unfortunately the synchronizer methods don't seem to be called when the > transaction is executed, and I don't see the output from those functions. > > Could someone point me in the right direction here on how to get these to > work? Here is my full code if anyone wants to take a look: > https://gist.github.com/countvajhula/4966286 > > Thanks, > -Sid > > -- > You received this message because you are subscribed to the Google Groups > "pylons-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pylons-devel+unsubscr...@googlegroups.com. > To post to this group, send email to pylons-devel@googlegroups.com. > Visit this group at http://groups.google.com/group/pylons-devel?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-devel+unsubscr...@googlegroups.com. To post to this group, send email to pylons-devel@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.