equal
deleted
inserted
replaced
65 """return 1 when repository is running in repair mode""" |
65 """return 1 when repository is running in repair mode""" |
66 return req.vreg.config.repairing |
66 return req.vreg.config.repairing |
67 |
67 |
68 |
68 |
69 class transaction(object): |
69 class transaction(object): |
70 """Ensure that the transaction is either commited or rollbacked at exit |
70 """Ensure that the transaction is either commited or rolled back at exit |
71 |
71 |
72 Context manager to enter a transaction for a session: when exiting the |
72 Context manager to enter a transaction for a session: when exiting the |
73 `with` block on exception, call `session.rollback()`, else call |
73 `with` block on exception, call `session.rollback()`, else call |
74 `session.commit()` on normal exit |
74 `session.commit()` on normal exit |
75 """ |
75 """ |
367 |
367 |
368 :attr:`commit_state`, describing the transaction commit state, may be one |
368 :attr:`commit_state`, describing the transaction commit state, may be one |
369 of None (not yet committing), 'precommit' (calling precommit event on |
369 of None (not yet committing), 'precommit' (calling precommit event on |
370 operations), 'postcommit' (calling postcommit event on operations), |
370 operations), 'postcommit' (calling postcommit event on operations), |
371 'uncommitable' (some :exc:`ValidationError` or :exc:`Unauthorized` error |
371 'uncommitable' (some :exc:`ValidationError` or :exc:`Unauthorized` error |
372 has been raised during the transaction and so it must be rollbacked). |
372 has been raised during the transaction and so it must be rolled back). |
373 |
373 |
374 Hooks controls: |
374 Hooks controls: |
375 |
375 |
376 :attr:`hooks_mode`, may be either `HOOKS_ALLOW_ALL` or `HOOKS_DENY_ALL`. |
376 :attr:`hooks_mode`, may be either `HOOKS_ALLOW_ALL` or `HOOKS_DENY_ALL`. |
377 |
377 |
784 |
784 |
785 :attr:`commit_state`, describing the transaction commit state, may be one |
785 :attr:`commit_state`, describing the transaction commit state, may be one |
786 of None (not yet committing), 'precommit' (calling precommit event on |
786 of None (not yet committing), 'precommit' (calling precommit event on |
787 operations), 'postcommit' (calling postcommit event on operations), |
787 operations), 'postcommit' (calling postcommit event on operations), |
788 'uncommitable' (some :exc:`ValidationError` or :exc:`Unauthorized` error |
788 'uncommitable' (some :exc:`ValidationError` or :exc:`Unauthorized` error |
789 has been raised during the transaction and so it must be rollbacked). |
789 has been raised during the transaction and so it must be rolled back). |
790 |
790 |
791 .. automethod:: cubicweb.server.session.Session.commit |
791 .. automethod:: cubicweb.server.session.Session.commit |
792 .. automethod:: cubicweb.server.session.Session.rollback |
792 .. automethod:: cubicweb.server.session.Session.rollback |
793 .. automethod:: cubicweb.server.session.Session.close |
793 .. automethod:: cubicweb.server.session.Session.close |
794 .. automethod:: cubicweb.server.session.Session.closed |
794 .. automethod:: cubicweb.server.session.Session.closed |
1231 self._touch() |
1231 self._touch() |
1232 self.debug('commit session %s done (no db activity)', self.id) |
1232 self.debug('commit session %s done (no db activity)', self.id) |
1233 return |
1233 return |
1234 cstate = self.commit_state |
1234 cstate = self.commit_state |
1235 if cstate == 'uncommitable': |
1235 if cstate == 'uncommitable': |
1236 raise QueryError('transaction must be rollbacked') |
1236 raise QueryError('transaction must be rolled back') |
1237 if cstate is not None: |
1237 if cstate is not None: |
1238 return |
1238 return |
1239 # on rollback, an operation should have the following state |
1239 # on rollback, an operation should have the following state |
1240 # information: |
1240 # information: |
1241 # - processed by the precommit/commit event or not |
1241 # - processed by the precommit/commit event or not |