fix constraint hook: a session may be involved in multiple transaction at time stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 09 Feb 2010 12:37:47 +0100
branchstable
changeset 4514 5bb1d39ea0da
parent 4505 a82af6b000f2
child 4515 e8835c68f581
fix constraint hook: a session may be involved in multiple transaction at time
server/hooks.py
--- a/server/hooks.py	Mon Feb 08 15:28:34 2010 +0100
+++ b/server/hooks.py	Tue Feb 09 12:37:47 2010 +0100
@@ -27,7 +27,6 @@
                                 'wf_info_for', 'from_state', 'to_state'))
 
 _UNIQUE_CONSTRAINTS_LOCK = Lock()
-_UNIQUE_CONSTRAINTS_HOLDER = None
 
 class _ReleaseUniqueConstraintsHook(Operation):
     def commit_event(self):
@@ -44,19 +43,17 @@
     RQLUniqueConstraint in two different transactions, as explained in
     http://intranet.logilab.fr/jpl/ticket/36564
     """
-    global _UNIQUE_CONSTRAINTS_HOLDER
     asession = session.actual_session()
-    if _UNIQUE_CONSTRAINTS_HOLDER is asession:
+    if 'uniquecstrholder' in asession.transaction_data:
         return
     _UNIQUE_CONSTRAINTS_LOCK.acquire()
-    _UNIQUE_CONSTRAINTS_HOLDER = asession
+    asession.transaction_data['uniquecstrholder'] = True
     # register operation responsible to release the lock on commit/rollback
     _ReleaseUniqueConstraintsHook(asession)
 
 def _release_unique_cstr_lock(session):
-    global _UNIQUE_CONSTRAINTS_HOLDER
-    if _UNIQUE_CONSTRAINTS_HOLDER is session:
-        _UNIQUE_CONSTRAINTS_HOLDER = None
+    if 'uniquecstrholder' in session.transaction_data:
+        del session.transaction_data['uniquecstrholder']
         _UNIQUE_CONSTRAINTS_LOCK.release()