# HG changeset patch # User Julien Cristau # Date 1371117839 -7200 # Node ID 63cf580accfce4437198a8c2ad8f6c2443b01650 # Parent a3594bf2b6bf7b5618134a01e2967ac558dc9efa notification: properly handle cnx and lifetime of the hijacked session When we create a session for the notification rendering, we need to 1) give it a cnxset 2) commit and close it after we're done 3) restore the original session for subsequent notifications This changes the ordering of actual mail sending, since there are several different commits involved, but I don't see a way to fix that short of restoring hijack_user. Related to #2934523 diff -r a3594bf2b6bf -r 63cf580accfc sobjects/notification.py --- a/sobjects/notification.py Wed Jun 12 12:27:00 2013 +0200 +++ b/sobjects/notification.py Thu Jun 13 12:03:59 2013 +0200 @@ -120,6 +120,7 @@ if isinstance(something, Entity): # hi-jack self._cw to get a session for the returned user self._cw = Session(something, self._cw.repo) + self._cw.set_cnxset() emailaddr = something.cw_adapt_to('IEmailable').get_email() else: emailaddr, lang = something @@ -143,6 +144,10 @@ msg = format_mail(self.user_data, [emailaddr], content, subject, config=self._cw.vreg.config, msgid=msgid, references=refs) yield [emailaddr], msg + if isinstance(something, Entity): + self._cw.commit() + self._cw.close() + self._cw = req # restore language req.set_language(origlang)