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
--- 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)