# HG changeset patch # User Philippe Pepiot # Date 1490630247 -7200 # Node ID 3ae16f70add4ea8c3acb45dafd55a97ec3d4210d # Parent 07d75be1bb8898dc38c931b0ab6d9d0e7912cec3 [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. diff -r 07d75be1bb88 -r 3ae16f70add4 cubicweb/hooks/test/unittest_hooks.py --- 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() diff -r 07d75be1bb88 -r 3ae16f70add4 cubicweb/server/session.py --- 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)