Пример #1
0
def _force_leave(db_name):
    try:
        transaction.set_clean(using=db_name)
        transaction.leave_transaction_management(using=db_name)
    except:
        _logger.error('force leave error: %s', db_name)
        _logger.except_error()
Пример #2
0
def _force_leave(db_name):
    try:
        transaction.set_clean(using=db_name)
        transaction.leave_transaction_management(using=db_name)
    except:
        _logger.error('force leave error: %s', db_name)
        _logger.except_error()
Пример #3
0
    def process_response(self, request, response):
        """Commit or abort the transaction after processing the response.

        On successful completion of the request, the transaction will
        be committed.

        As an exception to this, if the L{STORM_COMMIT_SAFE_METHODS}
        setting is False, and the request used either of the GET and
        HEAD methods, the transaction will be aborted.
        """
        from django.db import transaction as django_transaction
        # If process_exception() has been called, then we'll no longer
        # be in managed transaction mode.
        if django_transaction.is_managed():
            if self.commit_safe_methods or (
                request.method not in ['HEAD', 'GET']):
                try:
                    transaction.commit()
                except Exception:
                    transaction.abort()
                    raise
            else:
                transaction.abort()
            django_transaction.set_clean()
            django_transaction.leave_transaction_management()
        return response
Пример #4
0
    def process_response(self, request, response):
        """Commit or abort the transaction after processing the response.

        On successful completion of the request, the transaction will
        be committed.

        As an exception to this, if the L{STORM_COMMIT_SAFE_METHODS}
        setting is False, and the request used either of the GET and
        HEAD methods, the transaction will be aborted.
        """
        from django.db import transaction as django_transaction
        # If process_exception() has been called, then we'll no longer
        # be in managed transaction mode.
        if django_transaction.is_managed():
            if self.commit_safe_methods or (request.method
                                            not in ['HEAD', 'GET']):
                try:
                    transaction.commit()
                except Exception:
                    transaction.abort()
                    raise
            else:
                transaction.abort()
            django_transaction.set_clean()
            django_transaction.leave_transaction_management()
        return response
Пример #5
0
    def __enter__(self):
        self.was_dirty = dtransaction.is_dirty()
        self.old_connection = connection.connection

        connection.connection = self.connection

        dtransaction.enter_transaction_management()
        dtransaction.managed(True)
        dtransaction.set_clean()
Пример #6
0
 def _leave(self, db_name, con):
     if self._has_xid(db_name):
         # xa commit / xa rollback 共にされていない場合は接続を切る
         # con.close() を呼ぶと, 下記が発生し try で捕捉できない.
         # ProgrammingError: closing a closed connection
         connections[db_name].connection = None
         _logger.error('_leave: con has not xid')
     else:
         with self._open_cursor(con) as cur:
             self._set_transaction_isolation_level(cur, 'REPEATABLE READ')
         _logger.info('leave_transaction_management: %s', db_name,
                      verbose=self._verbose)
         transaction.set_clean(using=db_name)
         transaction.leave_transaction_management(using=db_name)
Пример #7
0
 def _leave(self, db_name, con):
     if self._has_xid(db_name):
         # xa commit / xa rollback 共にされていない場合は接続を切る
         # con.close() を呼ぶと, 下記が発生し try で捕捉できない.
         # ProgrammingError: closing a closed connection
         connections[db_name].connection = None
         _logger.error('_leave: con has not xid')
     else:
         with self._open_cursor(con) as cur:
             self._set_transaction_isolation_level(cur, 'REPEATABLE READ')
         _logger.info('leave_transaction_management: %s',
                      db_name,
                      verbose=self._verbose)
         transaction.set_clean(using=db_name)
         transaction.leave_transaction_management(using=db_name)
Пример #8
0
 def process_exception(self, request, exception):
     """Abort the transaction on errors."""
     from django.db import transaction as django_transaction
     transaction.abort()
     django_transaction.set_clean()
     django_transaction.leave_transaction_management()