[server] don't catch exception from postcommit_event() if we are in test mode
The historic behavior is to hide potential exception occurring in
postcommit_event(). Unfortunately logging statements are hidden by default
during tests and it become very hard to debug. At least raise if we are in test
mode.
--- a/cubicweb/hooks/test/unittest_hooks.py Fri Mar 24 14:18:17 2017 +0100
+++ b/cubicweb/hooks/test/unittest_hooks.py Mon Mar 27 17:57:27 2017 +0200
@@ -30,6 +30,7 @@
from cubicweb import ValidationError
from cubicweb.devtools.testlib import CubicWebTC
+from cubicweb.server.hook import Operation
class CoreHooksTC(CubicWebTC):
@@ -217,6 +218,21 @@
'login': u'login is part of violated unicity constraint'})
+class OperationTC(CubicWebTC):
+
+ def test_bad_postcommit_event(self):
+
+ class BadOp(Operation):
+ def postcommit_event(self):
+ raise RuntimeError('this is bad')
+
+ with self.admin_access.cnx() as cnx:
+ BadOp(cnx)
+ with self.assertRaises(RuntimeError) as cm:
+ cnx.commit()
+ self.assertEqual(str(cm.exception), 'this is bad')
+
+
if __name__ == '__main__':
import unittest
unittest.main()
--- a/cubicweb/server/session.py Fri Mar 24 14:18:17 2017 +0100
+++ b/cubicweb/server/session.py Mon Mar 27 17:57:27 2017 +0200
@@ -852,6 +852,8 @@
try:
operation.handle_event('postcommit_event')
except BaseException:
+ if self.repo.config.mode == 'test':
+ raise
self.critical('error while postcommit',
exc_info=sys.exc_info())
self.debug('postcommit transaction %s done', self)