[server] Make internal sessions not reset 'safe'-ness on first commit stable
authorJulien Cristau <julien.cristau@logilab.fr>
Thu, 26 Sep 2013 11:53:13 +0200
branchstable
changeset 9240 6356adcb652c
parent 9239 dde9fe1e0ce3
child 9241 cbee712dd310
[server] Make internal sessions not reset 'safe'-ness on first commit Increment the ctx_count when disabling integrity hooks so the next commit/rollback doesn't reset our transaction and magically turn us into a safe session. Closes #3168027
server/session.py
server/test/unittest_session.py
--- a/server/session.py	Mon Sep 23 11:13:28 2013 +0200
+++ b/server/session.py	Thu Sep 26 11:53:13 2013 +0200
@@ -1442,6 +1442,7 @@
         self.user._cw = self # XXX remove when "vreg = user._cw.vreg" hack in entity.py is gone
         if not safe:
             self.disable_hook_categories('integrity')
+            self._tx.ctx_count += 1
 
     def __enter__(self):
         return self
--- a/server/test/unittest_session.py	Mon Sep 23 11:13:28 2013 +0200
+++ b/server/test/unittest_session.py	Thu Sep 26 11:53:13 2013 +0200
@@ -25,6 +25,15 @@
         self.assertFalse(session.running_dbapi_query)
         session.close()
 
+    def test_integrity_hooks(self):
+        with self.repo.internal_session() as session:
+            self.assertEqual(HOOKS_ALLOW_ALL, session.hooks_mode)
+            self.assertEqual(set(('integrity',)), session.disabled_hook_categories)
+            self.assertEqual(set(), session.enabled_hook_categories)
+            session.commit()
+            self.assertEqual(HOOKS_ALLOW_ALL, session.hooks_mode)
+            self.assertEqual(set(('integrity',)), session.disabled_hook_categories)
+            self.assertEqual(set(), session.enabled_hook_categories)
 
 class SessionTC(CubicWebTC):