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