25 'wf_info_for', 'from_state', 'to_state')) |
25 'wf_info_for', 'from_state', 'to_state')) |
26 |
26 |
27 _UNIQUE_CONSTRAINTS_LOCK = Lock() |
27 _UNIQUE_CONSTRAINTS_LOCK = Lock() |
28 _UNIQUE_CONSTRAINTS_HOLDER = None |
28 _UNIQUE_CONSTRAINTS_HOLDER = None |
29 |
29 |
|
30 |
30 def _acquire_unique_cstr_lock(session): |
31 def _acquire_unique_cstr_lock(session): |
31 """acquire the _UNIQUE_CONSTRAINTS_LOCK for the session. |
32 """acquire the _UNIQUE_CONSTRAINTS_LOCK for the session. |
32 |
33 |
33 This lock used to avoid potential integrity pb when checking |
34 This lock used to avoid potential integrity pb when checking |
34 RQLUniqueConstraint in two different transactions, as explained in |
35 RQLUniqueConstraint in two different transactions, as explained in |
35 http://intranet.logilab.fr/jpl/ticket/36564 |
36 http://intranet.logilab.fr/jpl/ticket/36564 |
36 """ |
37 """ |
37 global _UNIQUE_CONSTRAINTS_HOLDER |
|
38 asession = session.actual_session() |
38 asession = session.actual_session() |
39 if _UNIQUE_CONSTRAINTS_HOLDER is asession: |
39 if 'uniquecstrholder' in asession.transaction_data: |
40 return |
40 return |
41 _UNIQUE_CONSTRAINTS_LOCK.acquire() |
41 _UNIQUE_CONSTRAINTS_LOCK.acquire() |
42 _UNIQUE_CONSTRAINTS_HOLDER = asession |
42 asession.transaction_data['uniquecstrholder'] = True |
43 # register operation responsible to release the lock on commit/rollback |
43 # register operation responsible to release the lock on commit/rollback |
44 _ReleaseUniqueConstraintsOperation(asession) |
44 _ReleaseUniqueConstraintsHook(asession) |
45 |
45 |
46 def _release_unique_cstr_lock(session): |
46 def _release_unique_cstr_lock(session): |
47 global _UNIQUE_CONSTRAINTS_HOLDER |
47 if 'uniquecstrholder' in session.transaction_data: |
48 if _UNIQUE_CONSTRAINTS_HOLDER is session: |
48 del session.transaction_data['uniquecstrholder'] |
49 _UNIQUE_CONSTRAINTS_HOLDER = None |
|
50 _UNIQUE_CONSTRAINTS_LOCK.release() |
49 _UNIQUE_CONSTRAINTS_LOCK.release() |
51 |
50 |
52 class _ReleaseUniqueConstraintsOperation(hook.Operation): |
51 class _ReleaseUniqueConstraintsOperation(hook.Operation): |
53 def commit_event(self): |
52 def commit_event(self): |
54 pass |
53 pass |